如图,比如这是数据库里的数据,我想得到每一天总的wait_time,比如12号总时间是7,13号总时间是10,如何书写sql语句
-- 以「年月日」分组,求sum(wait_time)即可
———了解思路,根据不同的数据库类型自行扩展!
以MySQL库为例:
-- 要求date_time是标准的日期型
SELECT
DATE_FORMAT(date_time, "%Y-%m-%d") as t,
SUM(wait_time) AS wait_time
FROM
tab_name
GROUP BY
DATE_FORMAT(date_time, "%Y-%m-%d")
select term,sum(vait_time) as wait_time_sum from (
select convert(varchar(10),date_time,120) as term,wait_time
from tablename
) a
group by term
sqlserver类似这样,tablename为表名。