我有一段永久旋轉的查詢。 我是DBA的新人。我想知道處理這些問題的第一件事是什麼?我查看了執行計劃 該表在ClassCode上只有1個非聚集索引。我使用這麼多ClassCode的原因是因爲在默認情況下,SSRS報告參數@ClassCode將是多個值,其中超過200個。如何提高查詢性能
SELECT PolicyNumber
FROM tblClassCodesPlazaCommercial
WHERE PolicyNumber NOT IN (
SELECT PolicyNumber
FROM tblClassCodesPlazaCommercial
WHERE ClassCode IN (
33489,31439,41894,68189,,01199,68528,67139,68128,739889,
33428,5561,68428,01484,5281,67227,01184,50199,23528,33283,03228,
50499,41594,50427,5181,31484,03199,6481,68239,50439,68489,36127,
50472,67128,23149,33439,03149,5452,23189,50228,01428,69183,50527,
67499,739189,50159,31183,33499,01283,33128,50239,6451,33159,
21199,67272,67127,69427,5451,23239,67199,67449,67189,01599,40228,
50184,5551,33299,7398,40179,40128,50139,7381,33199,50497,23428,33129,
738299,67149,40184,23128,69199,68499,50299,31449,40497,68169,67197,
5191,67259,5252,03489,67459,21299,5262,01181,03428,31483,68183,68228,
31199,40484,738199,03499,31499,40189,7382,67439,21527,50449,01427,
68199,5453,50528,36228,50259,68299,50227,23459,33528,40199,40427,
21289,42594,5283,34489,5251,21228,50197
)
)
在這種情況下,你需要別的0嗎?我期望值不在列表中的值將爲NULL,不= 0。但我可能錯了。無論哪種方式,比OP更好的主意。 – scsimon
@scsimon - 簡單的事實是'Count'聚合將不會計算'NULL'值。如果我在'else'部分添加'0',那麼count會認爲它是一個值並計算它,然後邏輯就會拋出 –
謝謝。沒有'NULL'ClassCode'。所以我應該把它放在'然後1'結尾。正確? – Oleg