ALTER PROCEDURE [dbo].[STOR_totalforadmin]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- Interfering with SELECT statements.
SET NOCOUNT ON;
-- SELECT * FROM tblDraw
SELECT tblretailer.ID,Name as retailername, tblretailer.AbcRate, tblretailer.AbRate,
tblretailer.BoxRate, tblretailer.StraightRate,
sum(isnull(ACount, 0)) as atotal ,
sum(isnull(BCount, 0)) as Btotal,
sum(isnull(CCount, 0)) as Ctotal,
SUM(isnull(Count,0)) as strtotal,
SUM(isnull(BoxCount,0)) as boxtotal,
SUM(isnull(ABCount,0))as abtotal,
SUM(isnull(ACCount,0))as actotal,
SUM(isnull(BCCount,0)) as bctotal
FROM tblretailer FULL JOIN Tbl_ABC abc ON (abc.RetailerID=tblretailer.ID)
FULL JOIN TblDraw Draw ON (Draw.RetailerID=tblretailer.ID)
FULL JOIN Tbl_ABACBC abbc ON (abbc.RetailerID=tblretailer.ID)
GROUP BY Name, tblretailer.ID, tblretailer.AbcRate, tblretailer.AbRate, tblretailer.BoxRate, tblretailer.StraightRate
END
2条答案
按热度按时间xbp102n01#
假设您有两个表,如下所示:
我们插入如下值:
首先,我们运行以下查询以获取摘要:
结果:
表1中的id 1的和值为10,但为什么结果是20?
然后运行以下查询(无摘要和分组依据):
结果:
因为我们使用
full join
,用录制Id = 1
在@table1
因为有两条记录Id = 1
在@表2中。iezvtpos2#
将总和除以3,如下所示:
为了所有人。