我在努力尝试减去SQL查询中的案例结果。你们能帮助我吗? 这是一个"简化"查询的版本。
SELECT dbo.tbla.cola, dbo.tblb.colb, dbo.tblb.colc,
CASE WHEN
(SELECT TOP 1 dstStart
FROM tblDst
WHERE tblcd.Key = dbo.tblDst.Key) >= DTimeU AND
(SELECT TOP 1 dstEnd
FROM tblDst
WHERE tblcd.Key = dbo.tblDst.Key) <= DTimeU
THEN tblcd.ApUtc + 1 ELSE tblcd.ApUtc END AS DepDST, CASE WHEN
(SELECT TOP 1 dstStart
FROM tblDst
WHERE tblca.Key = dbo.tblDst.Key) >= ATimeU AND
(SELECT TOP 1 dstEnd
FROM tblDst
WHERE tblca.Key = dbo.tblDst.Key) <= ATimeU THEN tblca.ApUtc + 1 ELSE tblca.ApUtc END AS ArrDST
FROM ...
WHERE ...
我如何执行(ArrDST-DepDST)作为DiffDST? 问候, 戴夫
答案 0 :(得分:0)
只需用另一个选择包装查询:
SELECT t.*, t.ArrDST - t.DepDST as DiffDST
FROM (YOUR QUERY HERE) t
然后所有计算的列都可以使用。