我有一个具有多个ID为给定的标准SQL表:MySQL的返回结果只有一个,而不是多个
mysql> select distinct id from FILTER where ft='f' and timestamp between '1367539200000' and '1367625599999';
+-----+
| id |
+-----+
| 0 |
| 121 |
| 122 |
| 124 |
| 125 |
| 127 |
+-----+
6 rows in set (0.00 sec)
mysql>
我想运行一个查询,将给予所有6列结果:
mysql> select a.id, count(a.id) as total, SUM(CASE WHEN b.result='0' THEN 1 ELSE 0 END) AS allowed, SUM(CASE WHEN b.result='1' THEN 1 ELSE 0 END) AS modified, SUM(CASE WHEN b.result='2' THEN 1 ELSE 0 END) AS blocked from FILTER a INNER JOIN EVENTS b on a.fid = b.event_id and a.timestamp = b.timestamp where b.protocol_type='MM4' and a.ft='f' and a.id in ('0', '121', '122', '124', '125', '127') and a.fid=b.event_id and b.timestamp between '1367539200000' and '1367625599999';
+----+-------+---------+----------+---------+
| id | total | allowed | modified | blocked |
+----+-------+---------+----------+---------+
| 0 | 216 | 0 | 135 | 81 |
+----+-------+---------+----------+---------+
1 row in set (0.01 sec)
mysql>
这只返回第一行。我可以确认的是,其他ID fulfuls的一个过滤条件(其实他们都做):
mysql> select a.id, count(a.id) as total, SUM(CASE WHEN b.result='0' THEN 1 ELSE 0 END) AS allowed, SUM(CASE WHEN b.result='1' THEN 1 ELSE 0 END) AS modified, SUM(CASE WHEN b.result='2' THEN 1 ELSE 0 END) AS blocked from FILTER a INNER JOIN EVENTS b on a.fid = b.event_id and a.timestamp = b.timestamp where b.protocol_type='MM4' and a.ft='f' and a.id='127' and a.fid=b.event_id and b.timestamp between '1367539200000' and '1367625599999';
+-----+-------+---------+----------+---------+
| id | total | allowed | modified | blocked |
+-----+-------+---------+----------+---------+
| 127 | 24 | 0 | 15 | 9 |
+-----+-------+---------+----------+---------+
1 row in set (0.00 sec)
mysql>
我也试过没有在名单:
mysql> select a.id, count(a.id) as total, SUM(CASE WHEN b.result='0' THEN 1 ELSE 0 END) AS allowed, SUM(CASE WHEN b.result='1' THEN 1 ELSE 0 END) AS modified, SUM(CASE WHEN b.result='2' THEN 1 ELSE 0 END) AS blocked from FILTER a INNER JOIN EVENTS b on a.fid = b.event_id and a.timestamp = b.timestamp where b.protocol_type='MM4' and a.ft='f' and a.fid=b.event_id and b.timestamp between '1367539200000' and '1367625599999';
+----+-------+---------+----------+---------+
| id | total | allowed | modified | blocked |
+----+-------+---------+----------+---------+
| 0 | 216 | 0 | 135 | 81 |
+----+-------+---------+----------+---------+
1 row in set (0.00 sec)
mysql>
我怎样才能改变我的过滤器为每个id显示6行而不是仅显示第一行?
一个
查找到'集团BY' – Lucas 2013-05-03 14:20:54