我有下表:
alertID inspectorID datelive dateread
1 none 2012-11-06 10:36:03.350 NULL
2 none 2012-11-06 10:36:25.043 NULL
3 none 2012-11-06 10:36:42.433 NULL
1 31030 2012-11-06 10:37:19.193 2012-06-11 10:34:47.000
我想选择没有检查员ID的警报以及警报ID与具有检查者ID的警报ID不匹配,即检查员已读取警报1所以我只希望它返回警报2 &安培; 3
使用经典ASP和MS-SQL
答案 0 :(得分:1)
试试这个
Select * From Alerts
Where AlertId Not In (Select AlertID From Alerts Where InspectorID IS NOT NULL)
我们的想法是知道哪些ID具有InspectorID,然后使用NOT IN
答案 1 :(得分:0)
SELECT *
FROM alertsTable
WHERE inspectorID IS NULL
AND alertID NOT IN (SELECT alertID FROM alertsTable where inspectorID IS NOT NULL)
答案 2 :(得分:0)
Select * From Table
Where alertID Not In
(Select alertID From Table Where inspectorID != 'none')