我有一张名为“订单”的表
clientID | order_status
client1 | pending
client1 | shipped
client2 | pending
client2 | complete
client3 | complete
client3 | shipped
client4 | pending
client4 | pending
client5 | shipped
client5 | shipped
client6 | complete
client6 | complete
我想选择任何具有“挂起”和“已发货”的order_status记录的clientID
此示例应仅返回“client1”
这是我的问题:
SELECT clientID
FROM orders
WHERE order_status IN("pending", "shipped")
GROUP BY clientID
HAVING COUNT(*) > 1
返回:
client1
client4
client5
我知道我需要使用 COUNT(DISTINCT order_status)但这是一个Microsoft Access数据库,我不确定如何正确实现它
答案 0 :(得分:1)
通常使用MSAccess中的内联视图进行处理。内联视图通过客户端为您提供不同的order_status,然后您可以计算。
SELECT clientID
FROM (SELECT ClientID, order_status
FROM orders
WHERE order_status IN("pending", "shipped")
GROUP BY clientID, order_status) B
GROUP BY ClientID
HAVING count(*) > 1
或者(因为我不喜欢没有聚合的小组)
SELECT clientID
FROM (SELECT Distinct ClientID, order_status
FROM orders
WHERE order_status IN("pending", "shipped")) B
GROUP BY ClientID
HAVING count(*) > 1
答案 1 :(得分:0)
你的问题
选择任何具有order_status记录的clientID "未决"并且"发货"
我认为查询语句应该使用和运算符一样的条件
Task.Run()