--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太长太乱,字段也没有贴出来,数据也没贴出来,估计别人都懒得去尝试。
建议,提高一下提问技巧。让别人立马能上手写sql尝试出来,最好。
把case都count起来试一下行不行,我猜的