mysql-如何从下表中获得项目总时数和活动总小时数之和

时间:2017-10-06 07:33:48

标签: mysql

表:team_activity

     act_id | act_dt    | act_activity   | act_total_duration
        1   |2017-03-03 | 2 i.e project  | 00:35:00
        2   |2017-03-03 | 2 i.e project  | 04:00:00
        3   |2017-03-03 | 1 i.e activity | 01:30:00
        4   |2017-03-03 | 2 i.e activity | 00:35:00
        5   |2017-03-04 | 2 i.e project  | 00:35:00
        6   |2017-03-04 | 2 i.e project  | 04:00:00
        7   |2017-03-04 | 1 i.e activity | 01:30:00
        8   |2017-03-04 | 2 i.e activity | 00:35:00

如何获得项目总小时数和act_dt为act_dt BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()的活动总小时数

如何获得项目总小时数和act_dt

的活动总小时数之和

我想要的结果是

act_dt     | total activity hours | Total project hours
2017-03-03 | 01:30:00             | 05:05:00
2017-03-04 | 01:30:00             | 06:00:00

SELECT *
      ,sum((TIME_TO_SEC(team_activity. act_total_duration) / 60))/60 as total_hours 
FROM team_activity 
where act_dt BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() 
and act_usr_id=27 
and act_activity=1 
GROUP BY act_dt 
union 
SELECT *
      ,sum((TIME_TO_SEC(team_activity. act_total_duration) / 60))/60 as total_hours 
FROM team_activity 
where act_dt BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW() 
and act_usr_id=27 
and act_activity=2 
GROUP BY act_dt

0 个答案:

没有答案