如何使用交叉应用获得更好的性能此SQL查询?
wsgi
答案 0 :(得分:2)
使用Group By
和Having
SELECT account_no
FROM Account
GROUP BY account_no
HAVING Count(CASE
WHEN status = 'P' THEN 1
END) = Count(1)
答案 1 :(得分:1)
似乎您需要所有状态均为“P”的帐号。不确定没有ORDER BY的TOP 10 ......
SELECT DISTINCT TOP 10 account_no
FROM Account a (NOLOCK)
WHERE NOT EXISTS(
SELECT 1 FROM account a1 (NOLOCK) WHERE a1.status <> 'P' AND a.Account_No = a1.Account_No)