标签:
答:即指定 GROUP BY 时,选择列表中任一非聚合表达式内的所有列都应包含在 GROUP BY 列表中,或者 GROUP BY表达式必须与选择列表表达式完全匹配。
2. case when then else end 语法的使用
select
i.index_name,i.index_def,
sum(case when w.years= 2014 then w.actual_value else 0 end) as a1,
sum(case when w.years= 2014 then w.ranking else 0 end ) as r1,
sum(case when w.years= (2014-1) then w.actual_value else 0 end ) as a2,
sum(case when w.years= (2014-1) then w.ranking else 0 end ) as r2,
from bm_work w,bm_index i
where
w.indexdef_id=i.uuid and
w.ent_id=‘2c90e4da49514c750149515eb56f0003‘ and w.summary_state=2
group by i.index_name,i.index_def;
这个语句达到这样一个效果
标签:
原文地址:http://blog.csdn.net/baicp3/article/details/42028629