gpt4 book ai didi

php - 使用多个值的内连接查询

转载 作者:行者123 更新时间:2023-11-29 01:23:17 24 4
gpt4 key购买 nike

我的表结构如图:

table:App
|AppID|AppName|AppType|
1 test new

table:AppRelease
|AppReleaseID|AppID|ReleaseDate|ReleaseVersion|
1 1 2012-06-20 2.2
2 1 2012-06-19 2.3

我写了一个如下所示的查询:

SELECT A.*,B.ReleaseDate,B.ReleaseVersion 
FROM App as A
LEFT JOIN AppRelease as B ON A.AppID=B.AppID

此查询适用于 AppRelease 表中的单个值,但 AppRelease 表中的多个值我想获得最后添加的值。是否可以在单个查询中?

最佳答案

SELECT aa.*, bb.AppReleaseID, bb.ReleaseDate
FROM App aa LEFT JOIN (
SELECT a.AppID, a.AppReleaseID, a.ReleaseDate
FROM AppRelease a INNER JOIN (
SELECT AppID, MAX(ReleaseDate) mx FROM AppRelease
GROUP BY AppID
) b ON a.AppID = b.AppID AND a.ReleaseDate = b.mx
) bb ON bb.AppID = aa.AppID

fiddle :http://sqlfiddle.com/#!2/befa2/3

关于php - 使用多个值的内连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11108230/

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