我有一个 sql 表,其中有多个 id 用于给定条件:
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 之一是否满足过滤条件(实际上它们都满足):
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 行,而不仅仅是第一行?
一个