我基本上是想在另一个查询的EXISTS IN子句中使用此结果解决方案一种方法:SELECT DISTINCT sc.StoreIdFROM StoreClients scWHERE NOT EXISTS( SELECT * FROM StoreClients sc2 WHERE sc2.StoreId = sc.StoreId AND sc2.ClientId = 5)How do I only select the stores that don't have client 5?StoreId ClientId ------- --------- 1 4 1 5 2 5 2 6 2 7 3 8I'm trying something like this:SELECT SC.StoreId FROM StoreClientsINNER JOIN StoreClients SC ON StoreClients.StoreId = SC.StoreId WHERE SC.ClientId = 5GROUP BY StoreClients.StoreIdThat seems to get me all the stores that have that client but I can't do the opposite because if I do <> 5 ill still get Store 1 and 2 which I don't want.I'm basically trying to use this result in another query's EXISTS IN clause 解决方案 One way:SELECT DISTINCT sc.StoreIdFROM StoreClients scWHERE NOT EXISTS( SELECT * FROM StoreClients sc2 WHERE sc2.StoreId = sc.StoreId AND sc2.ClientId = 5) 这篇关于如何在sql select中排除具有某些值的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-27 07:04