我不是开发人员,所以需要帮助重写这个查询没有内部连接,因为我认为这是核心问题。这段视频超过20秒。较小的块在一秒钟内运行。Pl的帮助。
select a.compID, b.InitialRT, b.VwRgts, b.UpdRgts, b.InsRgts, b.delRgts, b.Sscrnum , c.UserID
from tablecmpy a, tbldetrght b (nolock)
inner join tableuser c (nolock) on c.GroupID = b.UserId
where b.RecType='G'
and b.compID='[ALL]'
and b.InitialRT+b.VwRgts+b.UpdRgts+b.InsRgts+b.delRgts > 0
您已经在这里获得了笛卡尔连接(老式连接)from tablecmpy a, tbldetrght b (nolock)
。尝试使用:
SELECT a.compID,
b.InitialRT,
b.VwRgts,
b.UpdRgts,
b.InsRgts,
b.delRgts,
b.Sscrnum,
c.UserID
FROM tablecmpy a (nolock)
CROSS JOIN tbldetrght b (nolock)
INNER JOIN tableuser c (nolock)
ON c.GroupID = b.UserId
WHERE b.RecType='G'
AND b.compID='[ALL]'
AND COALESCE(b.InitialRT,0) +
COALESCE(b.VwRgts,0) +
COALESCE(b.UpdRgts,0) +
COALESCE(b.InsRgts,0) +
COALESCE(b.delRgts,0) > 0
我不知道在b.columns
中是否有NULL
,所以我添加了COALESCE来处理它们