我希望你能提供帮助,我需要总计TotalCapacity列给我一个基于Where Statement的总年数。我还需要看到彼此不同的年份。感谢
SELECT
Capacity.StartDate,
Capacity.EndDate,
DATEDIFF(d, Capacity.StartDate, Capacity.EndDate) + 1 AS DaysOpen,
Capacity.Capacity,
(DATEDIFF(d, Capacity.StartDate, Capacity.EndDate) + 1) * Capacity.Capacity AS TotalCapacity,
FROM
Capacity
WHERE
Capacity.StartDate >= '01 Jan 2010'
AND Capacity.EndDate <= '31 Dec 2010'
答案 0 :(得分:1)
猜猜你需要某种:
SELECT SUM(TotalCapacity)
FROM
(
SELECT
Capacity.StartDate
,Capacity.EndDate
,DATEDIFF(d, Capacity.StartDate, Capacity.EndDate) + 1 AS DaysOpen
,Capacity.Capacity
,(DATEDIFF(d, Capacity.StartDate, Capacity.EndDate) + 1) * Capacity.Capacity AS TotalCapacity
FROM
Capacity
WHERE Capacity.StartDate >= '01 Jan 2010' AND Capacity.EndDate <= '31 Dec 2010'
) t