我有一個具有多個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