0

我想将 timestampdiff 与最近的日期字段相加,所以我做了什么:

SUM(TIMESTAMPDIFF(SECOND, MAX(date), MAX(date_last_up))) as diff

原来这会触发 MySql 中的错误(组函数的无效使用),我必须删除该MAX()函数才能使其工作:

SUM(TIMESTAMPDIFF(SECOND, date, date_last_up)) as diff

有人知道如何使用 MAX() 函数来做到这一点吗?

4

1 回答 1

1

你可以这样做

   select yourcolumn , SUM(TIMESTAMPDIFF(SECOND, max_date, date_last_up)) 
  from (
         select yourcolumn , MAX(date) as max_date , MAX(date_last_up) as date_last_up
         WHERE ....
      )as t
   GROUP by yourcolumn
于 2013-07-02T10:36:15.953 回答