首页 > 数据库技术 > 详细

sql server 点滴累计

时间:2014-12-19 15:46:42      阅读:285      评论:0      收藏:0      [点我收藏+]

1.选择列表中的列无效,因为该列没有包含在聚合函数或 GROUP BY 子句中

答:即指定 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;

这个语句达到这样一个效果



sql server 点滴累计

原文:http://blog.csdn.net/baicp3/article/details/42028629

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!