gpt4 book ai didi

sql - 优化 "not in"查询

转载 作者:行者123 更新时间:2023-12-04 06:52:01 25 4
gpt4 key购买 nike

请帮助优化此查询:

SELECT ts.SiteId, COUNT(ts.SiteId) AS Count 
FROM ts
WHERE ts.SiteId not in
(SELECT ts.SiteId FROM ts WHERE ts.uniqueid = 'xxx')
GROUP BY ts.SiteId ORDER BY Count DESC

最佳答案

SELECT ts.SiteId, COUNT(ts.SiteId) AS Count, 
MAX(CASE WHEN ts.uniqueid = 'xxx' THEN 1 ELSE 0 END) As XXXUniqueID
FROM ts
GROUP BY ts.SiteId
HAVING XXXUniqueID = 0
ORDER BY Count DESC

关于sql - 优化 "not in"查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2987256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com