凝聚和自我加入

时间:2017-02-27 12:08:32

标签: join aggregation

嗨,我正在研究这个问题,想知道是否有一个好方法可以实现。 TableA as

zone_no   price     produceDate
54         12.33     20161201
58         7.88      20161224
64         28.27     20160812
67         20.45      20160405
87         14.08      20161102
92         1.69       20160101
101        12.57      20140501
141        22.21      20150601
157        14.28      20160417

select max(price) from tableA where zone_no between 54 and 145

select max(price) from tableA where Zone_no between 92 and 141

outcome: 
price(Zone 54-145)  price(zone 92-141)
28.27                   22.57

如何在没有CTE的情况下实现这一目标?感谢

1 个答案:

答案 0 :(得分:0)

替代解决方案

select sum(een), sum(twee) from (

select max(price) as een, 0 as twee from tableA where zone_no between 54 and 145
union
select 0, max(price) from tableA where Zone_no between 92 and 141

)