我正在尝试浏览一个表并获取mins
列的总和,但它总是告诉我mins
不是有效的列名
SELECT
acs.cid,
DATEDIFF (n, acs.StartTime, acs.EndTime ) as prepromomins,
CASE
WHEN (p.multiplier is null) THEN DATEDIFF (n , acs.StartTime, acs.EndTime)
ELSE (DATEDIFF ( n , acs.StartTime , acs.EndTime ) * p.multiplier)
END AS mins
FROM
activecards as acs
LEFT JOIN Promotions as p
ON acs.StartTime > p.StartTime and acs.EndTime < p.EndTime
答案 0 :(得分:0)
试试这个:
SELECT SUM(DATEDIFF(n, acs.StartTime, acs.EndTime) * ISNULL(p.multiplier,1)) AS TotalMins
FROM activecards as acs
LEFT JOIN Promotions as p
ON acs.StartTime > p.StartTime and acs.EndTime < p.EndTime