Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我对 SQL Select 查询有疑问。我需要计算属于具有一个或多个成本等于 1 的订单的帐户的订单。
这是结构:
任何人都可以帮助选择查询。结果应该是 2。非常感谢您的帮助。
您必须对表进行两个嵌套查询。外层计算一个账户的订单数量,内层计算至少有一个订单成本为 1 的账户。
SELECT Account_ID, COUNT(*) FROM Orders WHERE Account_ID IN (SELECT Account_ID FROM Orders WHERE PRODUCT_Cost = 1) GROUP BY Account_ID