sql - 你如何进行 Oracle SQL 查询

标签 sql oracle

这张表与普通模式相当落后,我不确定如何从中获取我需要的数据。

这里是一些示例数据,

Value (column)          Info (column)
---------------------------------------------
Supplier_1              'Some supplier'
Supplier_1_email        'foo@gmail.com'
Supplier_1_rating       '5'
Supplier_1_status       'Active'
Supplier_2              'Some other supplier'
Supplier_2_email        'bar@gmail.com'
Supplier_2_rating       '4'
Supplier_2_status       'Active'
Supplier_3              'Yet another supplier'

...

我需要查询以找到评级最高且当前状态为“有效”的供应商的电子邮件。

最佳答案

select 
    m.sup_email, r.sup_rating 
from 
    (select substr(value, 1, length(value) - length('_email') as sup_name, info as sup_email from table where value like '%_email') as m 
left join 
    (select substr(value, 1, length(value) - length('_rating') as sup_name), info as sub_rating from table where value like '%_rating') as r on m.sup_name = r.sup_name 
order by 
   sup_rating desc 
limit 
    1;

关于sql - 你如何进行 Oracle SQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3834125/

相关文章:

php - 设置mysql "search"页面

java - MySQL语句中根据另一个表列动态确定列值

java - 我的开发团队应该使用Hibernate吗?

oracle - 甲骨文-PLS-00382 : expression is of wrong type in subtracting dates

sql - 使用 Postgresql 更新

mysql - 根据日期字段更新时间戳列

Mysql 连接 5 个表或存储过程/函数

java - 按外键值查询而不是左连接

java - 如果 B 出错,则回滚 A。 Spring 启动,jdbctemplate

oracle - Oracle中 "most recent 20"表最有效的设计?