error_tbl success_tbl
id | creationTime id|creationTime
1 2014-09-23 10:03:40 1212 2014-09-23 10:02:40
1213 2014-09-23 10:03:40
1214 2014-09-23 10:10:40
查詢的運行之後,我想有這樣的:MySQL的選擇與時間範圍和條件
result table
creationTime | fail_ids | succ_ids
2014-09-23 10:03:40, 1, NULL
2014-09-23 10:02:40, NULL, 1212
2014-09-23 10:03:40, NULL, 1213
我想要的每個時間範圍內選擇的所有數據(成功和失敗)和每5分鐘只有在該時間段內有任何記錄存在於error_tbl中。
(SELECT
creationTime,
id as fail_ids,null as succ_ids
FROM error_tbl a
UNION
SELECT
creationTime,
null as fail_ids ,id as succ_ids
FROM success_tbl b
) s
」只有當error_tbl中存在任何記錄「=>'WHERE EXISTS(SELECT something FROM error_tbl WHERE ...)' – DanFromGermany 2014-09-23 12:45:26