为什么我这段sql一直显示这在查询,高手帮我看看代码是否有问题
SELECT mb.BUName 单位名称 ,
p.ProjName 项目名称 ,
ISNULL(SUM(s.Amount), 0) 计划销售金额 ,
ISNULL(SUM(c.HtTotal), 0) 实际销售金额 ,
( SELECT ISNULL(SUM(Amount), 0)
FROM dbo.s_Getin ,
dbo.s_Trade ,
dbo.p_Room
WHERE dbo.s_Getin.SaleGUID = dbo.s_Trade.TradeGUID
AND dbo.s_Trade.RoomGUID = dbo.p_Room.RoomGUID
AND dbo.p_Room.ProjGUID = s.ProjGUID
AND dbo.s_Getin.Status IS NULL
AND dbo.s_Getin.ItemName='楼款'
OR dbo.s_Getin.ItemName='定金'
OR dbo.s_Getin.ItemName='首期'
OR dbo.s_Getin.ItemName='补差款'
OR dbo.s_Getin.ItemName='银行按揭'
OR dbo.s_Getin.ItemName='公积金'
) ,
ISNULL(SUM(s.JHHKAmount), 0) 计划回款金额 ,
ISNULL(SUM(s.Bldarea), 0) 计划销售面积 ,
ISNULL(SUM(s.Rooms), 0) 计划销售套数
FROM dbo.s_SalesBudget s
INNER JOIN ( SELECT BUGUID ,
BUName
FROM dbo.e_myBusinessUnit
) mb ON mb.BUGUID = s.BUGUID
INNER JOIN ( SELECT ProjGUID ,
ProjName
FROM dbo.p_Project
) p ON p.ProjGUID = s.ProjGUID
LEFT JOIN ( SELECT ProjGUID ,
HtTotal ,
BldArea ,
Status
FROM dbo.s_Contract
WHERE Status = '激活'
) c ON c.ProjGUID = s.ProjGUID
WHERE (1=1)
GROUP BY mb.BUName ,
s.ProjGUID ,
p.ProjName
ORDER BY mb.BUName
[解决办法]
select * from sys.sysprocesses where blocked<>0
这种类型通常是有阻塞
[解决办法]
像版主说的,可能是阻塞问题,加上with(nolock)试试,下面已经给你加上了,你再运行试试,如果还是慢,那么说明应该不是阻塞问题,可能是语句写的太复杂了:
SELECT mb.BUName 单位名称 ,
p.ProjName 项目名称 ,
ISNULL(SUM(s.Amount), 0) 计划销售金额 ,
ISNULL(SUM(c.HtTotal), 0) 实际销售金额 ,
( SELECT ISNULL(SUM(Amount), 0)
FROM dbo.s_Getin with(nolock),
dbo.s_Trade with(nolock),
dbo.p_Room with(nolock)
WHERE dbo.s_Getin.SaleGUID = dbo.s_Trade.TradeGUID
AND dbo.s_Trade.RoomGUID = dbo.p_Room.RoomGUID
AND dbo.p_Room.ProjGUID = s.ProjGUID
AND dbo.s_Getin.Status IS NULL
AND dbo.s_Getin.ItemName='楼款'
OR dbo.s_Getin.ItemName='定金'
OR dbo.s_Getin.ItemName='首期'
OR dbo.s_Getin.ItemName='补差款'
OR dbo.s_Getin.ItemName='银行按揭'
OR dbo.s_Getin.ItemName='公积金'
) ,
ISNULL(SUM(s.JHHKAmount), 0) 计划回款金额 ,
ISNULL(SUM(s.Bldarea), 0) 计划销售面积 ,
ISNULL(SUM(s.Rooms), 0) 计划销售套数
FROM dbo.s_SalesBudget s with(nolock)
INNER JOIN ( SELECT BUGUID ,
BUName
FROM dbo.e_myBusinessUnit with(nolock)
) mb ON mb.BUGUID = s.BUGUID
INNER JOIN ( SELECT ProjGUID ,
ProjName
FROM dbo.p_Project with(nolock)
) p ON p.ProjGUID = s.ProjGUID
LEFT JOIN ( SELECT ProjGUID ,
HtTotal ,
BldArea ,
Status
FROM dbo.s_Contract with(nolock)
WHERE Status = '激活'
) c ON c.ProjGUID = s.ProjGUID
WHERE (1=1)
GROUP BY mb.BUName ,
s.ProjGUID ,
p.ProjName
ORDER BY mb.BUName