求助:请帮我看看我的sql语句问题出在哪里?
处理一个数据 结果是这个
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