Chinaunix
标题:
这样的case语句有什么问题,请高手帮忙急!!!
[打印本页]
作者:
trjf
时间:
2008-07-16 10:14
标题:
这样的case语句有什么问题,请高手帮忙急!!!
这样的case语句有什么问题,请高手帮忙急!!!
select a.acct_id,
(case when acct_month_id=\'200806\' then ys_charge else 0 end) charge1,
(case when acct_month_id=\'200806\' then yh_charge else 0 end) charge2,
(case when acct_month_id=\'200813\' then ys_charge else 0 end) charge3,
(case when acct_month_id=\'200813\' then yh_charge else 0 end) charge4
from acct_charge a
where a.acct_month_id in(\'200806\',\'200813\')
and acct_id=560000004
group by a.acct_id;
返回结果是:
+-----------+---------+---------+---------+----------+
| acct_id | charge1 | charge2 | charge3 | charge4 |
+-----------+---------+---------+---------+----------+
| 560000004 | 0 | 0 | 4415.57 | -4752.19 |
+-----------+---------+---------+---------+----------+
1 row in set
但
select * from acct_charge a where acct_id=\'560000004\' and a.acct_month_id in(\'200806\',\'200813\')
返回如下:
+------+-----------+---------------+-----------+-----------+
| id | acct_id | acct_month_id | ys_charge | yh_charge |
+------+-----------+---------------+-----------+-----------+
| 3000 | 560000004 | 200813 | 4415.57 | -4752.19 |
| 3004 | 560000004 | 200806 | 1048.7 | -768.79 |
+------+-----------+---------------+-----------+-----------+
2 rows in set
为什么case中用in语句只能返回最后的一个语句的值
作者:
wdx-snail
时间:
2008-07-16 12:48
因为你group by a.acct_id
两个记录的a.acct_id是一样的。
作者:
atgc
时间:
2008-07-20 16:04
如楼上说的,被你group掉了
作者:
yueliangdao0608
时间:
2008-07-27 10:16
where a.acct_month_id in(\'200806\',\'200813\')
因为你的month_id类型是整型,不是字符串!
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2