首页 > 解决方案 > 在 SELECT [MYSQL] 中加入或选择

问题描述

请帮我加入这两个选择:

SELECT IFNULL(sum(estimated_hours * t2.man_hour),0) as 
estimated from project_has_tasks t1 left join users t2 
on t1.user_id = t2.id group by project_id

SELECT IFNULL(sum(TIME_FORMAT(SEC_TO_TIME 
(time_spent),'%k.%i' )* t2.man_hour),0) as time_spent_cost FROM project_has_tasks t1
left join users t2 on t1.user_id = t2.id group
 by project_id

想要获得:

| estimated | time_spent_cost |
_______________________________
| 000000000 |    00000000     |

标签: mysqljoinselect

解决方案


只需将它们放在一个查询中:

SELECT IFNULL(sum(estimated_hours * t2.man_hour),0) as 
estimated, IFNULL(sum(TIME_FORMAT(SEC_TO_TIME 
(time_spent),'%k.%i' )* t2.man_hour),0) as time_spent_cost
from project_has_tasks t1 left join users t2 
on t1.user_id = t2.id group by project_id

推荐阅读