- 论坛徽章:
- 0
|
这样的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语句只能返回最后的一个语句的值 |
|