我需要在我的sql表中找到始终只出现在某个值中的条目.
例如:
DeviceID Transmission
-------- ------------
000329 Inventory
000980 Inventory
004406 Starting
000980 Stopping
000329 Inventory
004406 Inventory
现在我需要找到所有只有库存传输且从不启动或停止的DeviceID.在这种情况下000329.
最佳答案
您可以选择所有Transmission =’Inventory’id并过滤掉Transmission中的(‘Starting’,’Stopping’):
select distinct(DeviceID) from YourTable
WHERE Transmission = 'Inventory'
and DeviceID not in
( select distinct(DeviceID) from YourTable
WHERE Transmission in('Starting','Stopping')
);