首页 新闻 会员 周边

SQL 字段求和,挺急的,在线等

0
悬赏园豆:10 [已解决问题] 解决于 2017-08-16 11:37

--ok 发货异常总得分 =(0笔+ (1-10笔)+ (11-20笔)(21-30笔)+ (>30笔) )
select * from(
select mpa02 as '档口', count (distinct(stq03)) as '发货异常笔数' ,
(case when count(distinct(stq03))='0' then '15' else '0' end ) as '发货异常0笔得分' ,
(case when count(distinct(stq03))>='1' and count (distinct(stq03)) <'10' then '14' else '0' end ) as '发货异常1-10笔得分' ,
(case when count (distinct(stq03)) >='11' and count (distinct(stq03)) <'20' then '13' else '0' end ) as '发货异常11-20笔得分',--13 '发货异常11-20笔'
(case when count (distinct(stq03)) >='21' and count (distinct(stq03)) <'30' then '11' else '0' end ) as '发货异常21-30笔得分',--11 '发货异常21-30笔'
(case when count (distinct(stq03)) >='30' then '1' else '0' end ) as '发货异常大于30笔得分' --10 '发货异常大于30笔'
from mpa_file left join stq_file on mpa01=stq03
where mpa02='ZLDZSW' and (mpa04>='2017-7-8' and mpa04<'2017-08-12')
and mpaacti='Y' and mpa03>='3' and mpa01 like 'MP%' group by mpa02

 

请问下,我想把2-6列 求和 并 在这个表后面 加个字段显示出来 应该怎么写SQL语句啊

SQL
男人要爽的主页 男人要爽 | 初学一级 | 园豆:6
提问于:2017-08-15 16:17
< >
分享
最佳答案
1

sql太长太乱,字段也没有贴出来,数据也没贴出来,估计别人都懒得去尝试。

建议,提高一下提问技巧。让别人立马能上手写sql尝试出来,最好。

收获园豆:5
hahanonym | 小虾三级 |园豆:1460 | 2017-08-16 10:03
其他回答(1)
0

把case都count起来试一下行不行,我猜的

收获园豆:5
Will_D_Zhang | 园豆:213 (菜鸟二级) | 2017-08-15 19:28
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册