我的查询结果会带回许多内容,名称,标题,聚合,计数等。 我只需要在最后四列的底部有一个TOTAL ROW:
AE Client Priority Contract LineNumber Zone Network Days Time Parameter Total Spots Required Cost Per Spot Required Rev
Doe, John Dummy Client 2 153370 37 Atlanta AMC MTWTFSS 19:00 - 00:00 38 1 1 1
Doe, John Dummy Client 2 153370 40 Atlanta AMC MTWTFSS 19:00 - 00:00 38 1 2 3
Doe, John Dummy Client 2 153370 253 Atlanta ESPN MTWTFSS 19:00 - 00:00 33 5 3 5
Doe, John Dummy Client 2 153370 256 Atlanta ESPN MTWTFSS 19:00 - 00:00 33 3 4 7
Doe, John Dummy Client 2 153370 391 Atlanta GOLF MTWTFSS 19:00 - 00:00 35 1 5 9
Doe, John Dummy Client 2 153370 412 Atlanta HALL MTWTFSS 19:00 - 00:00 42 3 6 11
219 14 21 36
我一直在尝试使用ROLLUP()或WITH ROLLUP,但它会将我的行分开。我提供了我的整个查询,因为我不想让一些小东西搞砸我,并通过总结它来错过它。
Set DATEFIRST 1
SELECT
AE.LastName+', '+AE.FirstName as 'AE',
Client.Name as 'Client',
Eventmaster.PriorityID as 'Priority',
Conline.ConID as 'Contract',
Conline.LineNum as 'LineNumber',
Zone.Name as 'Zone',
Network.Name as 'Network',
((CASE
WHEN Conline.monday = '1'
THEN 'M'
ELSE '-'
END)+
(CASE
WHEN Conline.Tuesday = '1'
THEN 'T'
ELSE '-'
END)+
(CASE
WHEN Conline.Wednesday = '1'
THEN 'W'
ELSE '-'
END)+
(CASE
WHEN Conline.Thursday = '1'
THEN 'T'
ELSE '-'
END)+
(CASE
WHEN Conline.Friday = '1'
THEN 'F'
ELSE '-'
END)+
(CASE
WHEN Conline.Saturday = '1'
THEN 'S'
ELSE '-'
END)+
(CASE
WHEN Conline.Sunday = '1'
THEN 'S'
ELSE '-'
END)) as 'Days',
(Left(Convert(Time, DATEADD(ss,Conline.StartTime, 0),0),5))+' - '+(Left(Convert(Time, DATEADD(ss,Conline.StopTime, 0),0),5)) as 'Time Parameter',
Conline.TotalSpots as 'Total Spots',
COUNT(EventMaster.Status) as 'Required',
Conline.Cost as 'Cost Per Spot',
Conline.Cost * count(eventmaster.status) as 'Required Rev'
FROM EventMaster
inner join Conline on
EventMaster.ConlineID = Conline.ConlineID
inner join Contract on
Conline.ConID = Contract.ConID
inner join Zone on
Conline.ZoneID = Zone.ZoneID
inner join Network on
Conline.NetworkID = Network.NetworkID
inner join AE on
Contract.AEID = AE.AEID
inner join Client on
Contract.ClientID = Client.ClientID
WHERE
Conline.StartDate >= 19862
and Conline.StopDate <= 19889
and EventMaster.Status = 'R'
and Network.Name NOT IN ('iATT', 'XCSV', 'XCSB','ICOX', 'ISYN', 'ICHT', 'LO3FLO', 'LO3HUNT', 'LO96', 'LOFE', 'INFO', 'IFXN', 'DMAN', 'SMS','VODT','RRR', 'RFI', 'LO', 'NPRD', 'CONT', 'PROD', 'RETL', 'VHXB', 'WEBO', 'INFOMERC','MISC-PKG','WEBB', 'VHXL','AUTO', 'CRWL', 'FEAT', 'LA 46', 'LEASE2', 'LO Knox')
--and Eventmaster.ClientID <> '7777'
and EventMaster.PriorityID = '2'
and totalspots > '0'
and EventMaster.Deleted <> '1'
GROUP BY
AE.LastName,
AE.FirstName,
Client.Name,
Eventmaster.PriorityID,
Conline.ConID,
Conline.LineNum,
Zone.Name,
Network.Name,
Conline.TotalSpots,
Conline.Monday,
Conline.Tuesday,
Conline.Wednesday,
Conline.Thursday,
Conline.Friday,
Conline.Saturday,
Conline.Sunday,
Conline.StartTime,
Conline.StopTime,
conline.cost
ORDER BY
AE.LastName,
Conline.ConID,
Zone.Name
SET DATEFIRST 7
看起来它可能一直在尝试为每行下方的每个Conline.LineNum提供一个总计,但我需要整个查询的总数。
答案 0 :(得分:0)
你可以通过union子句来做到这一点。但是union只适用于相同的属性,所以你也可以使用另一个空值。像这样的事情: -
SELECT YOUR PREVIOUS QUERY
UNION
SELECT SUM(FIRST_COL), SUM(SECOND_COL), SUM(THIRD_COL), SUM(FOURTH_COL),
NULL,NULL,NULL,...........
我不确定,但我认为这种方法可以解决您的问题。