我想在结果中每天更改日期。怎么可能
例如:
哪里
REPLY_dATE
BETWEEN'2017-03-17 12:00:00 AM'和'2017-03-17 4:00:00 PM
我想替换===== 2017-01-01 12:00:00 AM ==== today_Date
2017-03-17 4:00:00 PM =======当前日期
答案 0 :(得分:0)
第一步使用LEAST()
:
LEAST(264, Round(SUM(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE))/480)) as WH
使用CASE
进行第二步:
CASE WHEN ROUND((126720-sum(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE)))/480) < 0 THEN 0
ELSE LEAST(264, Round(SUM(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE))/480))
END
如果您还需要WH
和VH
,则可以使用子查询来避免冗余:
SELECT VH, WH,
CASE
WHEN (SELECT VH) < 0 THEN 0
ELSE (SELECT WH)
END AS MyComputedColumn
FROM
(
SELECT
ROUND((126720-sum(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE)))/480) as VH,
LEAST(264, Round(SUM(TIMESTAMPDIFF(MINUTE,Request_Date, REPLY_dATE))/480)) as WH
FROM bbt2.new_table
) AS X;