求助:请帮我看看我的sql语句问题出在哪里?
时间:2011-12-02
来源:互联网
处理一个数据 结果是这个
CASHIER_NO A6 A7
0 575 1069
16000006 0 22
16000034 4 11
16000037 125 35
16000091 39 40
16000652 32 0
16000659 755 540
16000668 0 559
16000669 43 57
16000670 598 332
但是我写的时候出现的是这个结果
CASHIER_NO A6 A7 A8 A9 A10 A11
0 575
0 1069
0 1193
0 745
0 1062
0 577
16000006 22
16000006 28
16000006 26
16000006 29
16000006 30
16000034 4
16000034 11
16000034 14
16000034 8
16000034 7
16000034 8
16000037 125
16000037 35
我写的语句如下
select cashier_no,
case when substr(shift_date,5,2 )='06' then count(exchange_no) else null end a6,
case when substr(shift_date,5,2 )='07' then count(exchange_no) else null end a7,
case when substr(shift_date,5,2 )='08' then count(exchange_no) else null end a8,
case when substr(shift_date,5,2 )='09' then count(exchange_no) else null end a9,
case when substr(shift_date,5,2 )='10' then count(exchange_no) else null end a10,
case when substr(shift_date,5,2 )='11' then count(exchange_no) else null end a11
from huaian.sto_sale_master
where shift_date between '20110601' and '20111130'
and cancel_flag='0'
group by cashier_no,substr(shift_date,5,2 )
ORDER BY cashier_no
请看看我的问题在哪里
CASHIER_NO A6 A7
0 575 1069
16000006 0 22
16000034 4 11
16000037 125 35
16000091 39 40
16000652 32 0
16000659 755 540
16000668 0 559
16000669 43 57
16000670 598 332
但是我写的时候出现的是这个结果
CASHIER_NO A6 A7 A8 A9 A10 A11
0 575
0 1069
0 1193
0 745
0 1062
0 577
16000006 22
16000006 28
16000006 26
16000006 29
16000006 30
16000034 4
16000034 11
16000034 14
16000034 8
16000034 7
16000034 8
16000037 125
16000037 35
我写的语句如下
select cashier_no,
case when substr(shift_date,5,2 )='06' then count(exchange_no) else null end a6,
case when substr(shift_date,5,2 )='07' then count(exchange_no) else null end a7,
case when substr(shift_date,5,2 )='08' then count(exchange_no) else null end a8,
case when substr(shift_date,5,2 )='09' then count(exchange_no) else null end a9,
case when substr(shift_date,5,2 )='10' then count(exchange_no) else null end a10,
case when substr(shift_date,5,2 )='11' then count(exchange_no) else null end a11
from huaian.sto_sale_master
where shift_date between '20110601' and '20111130'
and cancel_flag='0'
group by cashier_no,substr(shift_date,5,2 )
ORDER BY cashier_no
请看看我的问题在哪里
作者: fair1982 发布时间: 2011-12-02
你是要不满足情况的填0么?
case when substr(shift_date,5,2 )='06' then count(exchange_no) else null end
改为
case when substr(shift_date,5,2 )='06' then count(exchange_no) else 0 end
后面的null都改为0即可
case when substr(shift_date,5,2 )='06' then count(exchange_no) else null end
改为
case when substr(shift_date,5,2 )='06' then count(exchange_no) else 0 end
后面的null都改为0即可
作者: zxf261 发布时间: 2011-12-06
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28