您能帮助我将两个查询合而为一吗?
这是我的第一个查询:

SELECT estimated_sum_all, story_point_sum_all, time_spent,  reg_date
FROM burndown_snap_all  WHERE project_id='72'


结果:

 | estimated_sum_all | story_point_sum_all | time_spent | reg_date |
 | 300               | 20                  | 20.30      | 2017-09  |
 | 300               | 20                  | 19.30      | 2017-09  |
 | 300               | 20                  | 18.30      | 2017-09  |
 | 300               | 20                  | 15.32      | 2017-09  |


这是我的第二个查询:

SELECT time_spent FROM status_history_hours where
project_id = '72'


结果:

| time_spent |
| 20.30      |
| 20.30      |
| 20.30      |
| 20.30      |


我想做的是建立一个MySQL查询,该查询必须包含第二个查询中的select / join to time_spent。决赛桌应如下所示:

 | estimated_sum_all | story_point_sum_all | time_spent | reg_date |
 | 300               | 20                  | 20.30      | 2017-09  |
 | 300               | 20                  | 20.30      | 2017-09  |
 | 300               | 20                  | 20.30      | 2017-09  |
 | 300               | 20                  | 20.30      | 2017-09  |


问候,

解决方案如下:

SELECT t1.id, t1.estimated_sum_all,
t1.story_point_sum_all, t1.time_spent,
t2.id, t2.time_spent FROM
burndown_snap_all t1, status_history_hours
t2 WHERE t1.project_id = 72 AND
t2.project_id = 72 group by t1.id


但是如何同时按t2.id分组呢?

最佳答案

SELECT estimated_sum_all, story_point_sum_all, time_spent,  reg_date
FROM burndown_snap_all  WHERE project_id='72'
UNION ALL
SELECT time_spent FROM status_history_hours where
project_id = '72'

关于mysql - 一个[MYSQL]中的两个查询一个结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46487181/

10-14 16:20
查看更多