gpt4 book ai didi

MYSQL同表Join操作

转载 作者:行者123 更新时间:2023-11-29 05:34:11 25 4
gpt4 key购买 nike

SELECT DISTINCT mp.Group_Name FROM measurement_test mt, measurement_point mp, measurement_values mv 
WHERE mt.Test_ID = mv.Test_ID AND mv.Point_ID = mp.Point_ID AND mt.ID_Number = 'WR20120603_05'


SELECT DISTINCT mp.Group_Name FROM measurement_test mt, measurement_point mp, measurement_values mv
WHERE mt.Test_ID = mv.Test_ID AND mv.Point_ID = mp.Point_ID AND mt.ID_Number = 'WR20120603_04'

以上是我在网页中使用的两个查询。实际上我只想获得两个查询之间结果的公共(public) group_name 值,是否有任何其他可能的方法来实现这个特定场景,或者简单地使用上述两个查询?

最佳答案

SELECT mp.Group_Name 
FROM measurement_test mt
inner join measurement_values mv on mt.Test_ID = mv.Test_ID
inner join measurement_point mp on mv.Point_ID = mp.Point_ID
WHERE mt.ID_Number in ('WR20120603_04', 'WR20120603_05')
group by mp.Group_Name
having count(distinct mt.ID_Number) = 2

关于MYSQL同表Join操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12154006/

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