设为首页 加入收藏

TOP

sqlserver点滴累计
2015-07-24 10:39:24 来源: 作者: 【 】 浏览:1
Tags:sqlserver 点滴 累计

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;

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇对于SQLSERVER中评估期已过的处理.. 下一篇RMAN的"rman: can't ope..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·请问c语言刚入门,该 (2025-12-26 10:21:04)
·python 编程怎么定义 (2025-12-26 10:21:01)
·09-指 针 (一)-c语言 (2025-12-26 10:20:58)
·About - Redis (2025-12-26 08:20:56)
·Redis: A Comprehens (2025-12-26 08:20:53)