如何获得更好的性能这个SQL查询?

时间:2017-04-17 05:18:28

标签: sql sql-server performance

如何使用交叉应用获得更好的性能此SQL查询?

wsgi

2 个答案:

答案 0 :(得分:2)

使用Group ByHaving

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)