- 论坛徽章:
- 93
|
回复 2# 林间笑客
数据里不存在的数据,即使你 in 里有写,也是不显示的。你实在要,你就做写一串的 0 加进去喽:
- mysql> select
- name,
- sum(case result when 0 then 1 else 0 end) result1,
- sum(case result when 1 then 1 else 0 end) result2,
- sum(case result when 2 then 1 else 0 end) result3
- from
- (
- select * from table1
- union
- select "ccnu", 0, 0
- ) as tmp
- where name in ('chen','wu','ccnu','li')
- group by name;
- +------+---------+---------+---------+
- | name | result1 | result2 | result3 |
- +------+---------+---------+---------+
- | ccnu | 1 | 0 | 0 |
- | chen | 0 | 0 | 1 |
- | li | 2 | 0 | 0 |
- | wu | 0 | 2 | 0 |
- +------+---------+---------+---------+
- 4 rows in set
复制代码
|
|