mysql - 在 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 |
解决方案
只需将它们放在一个查询中:
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
推荐阅读
- node.js - 使用调度程序播放音频时的 Discord.js 音乐机器人“TypeError”
- spring-kafka - 带有 @KafkaListener 注释的 kafka 消费者如何处理 max.poll.records
- reactjs - 在生产中找不到 React Router 投掷页面
- macos - 通过 MacOS High Sierra 中的终端以编程方式更改触摸栏设置
- python - 在 AWS SageMaker 上导入 fbprophet
- amazon-web-services - 从 lambda AWS 使用时 Dynamodb 没有响应
- python - 如何在 Omxplayer 上创建曲目列表
- python - 从 JSON 中提取粗体文本
- reactjs - react-router-dom PrivateRoute 与 redux 无限加载
- javascript - 如何使 Django 模型和视图将 JSON 数据传递到 MySQL 数据库?