SUM(数量)00:00 - 23.59昨天

时间:2015-09-21 10:48:54

标签: mysql

基于此,我如何设定整个00:00 - 23.59(昨天)的间隔

int

2 个答案:

答案 0 :(得分:2)

试一试 -

SELECT SUM(quantity)
    FROM downloads
WHERE
  date>=CONCAT(SUBDATE(CURDATE(), INTERVAL 1 DAY),' 00:00:00')
  AND date<= CONCAT(SUBDATE(CURDATE(), INTERVAL 1 DAY),' 23:59:59')

或者您可以使用 -

SELECT SUM(quantity)
    FROM downloads
WHERE
  date>=SUBDATE(CURDATE(), INTERVAL 1 DAY)
  AND date< CURDATE();

答案 1 :(得分:0)

您可以尝试这样:

SELECT SUM(quantity)
    FROM downloads
WHERE
  date = DATE_sub(date,INTERVAL 1 DAY);

了解更多信息:https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add