2017-05-27 48 views
0

這是一個有點棘手來解釋我後,但在這裏。我有2個表格需要參考software_releasesplatforms。軟件版本將包含平臺ID,軟件ID和版本號。獲取不同列值的最新條目

我想獲取每個不同平臺的最新版本號。

查詢,我現在有如下:

SELECT ReleaseID, 
     DateCreated, 
     SoftwareID, 
     platforms.PlatformID, 
     PlatformName, 
     VersionNumber 
FROM  software_releases, platforms 
WHERE software_releases.PlatformID = platforms.PlatformID 
AND  software_releases.SoftwareID='3' 
ORDER BY VersionNumber DESC 

將返回:

5 27/05/2017 22:37 3 7 Windows 3.0.0.0 
9 27/05/2017 22:56 3 7 Windows 2.6.0.0 
7 27/05/2017 22:46 3 5 Android 2.5.1.1 
1 27/05/2017 23:21 3 5 Android 2.5.0.0 

列順序如下:

  • ReleaseID
  • 發佈日期
  • 軟件ID
  • 平臺ID
  • 版本ID

我所尋找的是獲得用於指定的軟件ID返回每個平臺的最新版本,因此,我只是想返回以下:

5 27/05/2017 22:37 3 7 Windows 3.0.0.0 
7 27/05/2017 22:46 3 5 Android 2.5.1.1 

感謝您提供任何幫助。

+1

https://www.google.com/search?q=mysql+groupwise+maximum – CBroe

+0

@CBroe感謝,不知道這就是它被稱爲 - 是一個沒有這個棘手的事情谷歌 – Boardy

回答

0

我從CBrowe評論中得到了這個答案,我不知道我之後被稱爲一個明智的最大查詢。

我改變了我的查詢是

  SELECT * FROM (SELECT DateCreated, SoftwareID, software_releases.PlatformID, 
     VersionNumber, PlatformName FROM software_releases, platforms WHERE 
     SoftwareID='3' AND 
     platforms.PlatformID = software_releases.PlatformID ORDER BY VersionNumber DESC) 
     AS s GROUP BY PlatformID