如何将日期频繁更改(日复一日)

时间:2017-03-14 05:25:14

标签: mysql sql database

我想在结果中每天更改日期。怎么可能

例如: 哪里 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 =======当前日期

1 个答案:

答案 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 

如果您还需要WHVH,则可以使用子查询来避免冗余:

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;