1

我正在尝试遍历一个表并获取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
4

1 回答 1

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
于 2012-09-21T06:58:54.463 回答