gpt4 book ai didi

mysql - 两个查询合二为一 [MYSQL] 一个结果

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:19 26 4
gpt4 key购买 nike

你们能帮我把两个查询合二为一吗?这是我的第一个查询:

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 查询,该查询必须包含从第二个查询中选择/加入到 time_spent 的查询。决赛 table 应该是这样的:

 | 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com