我有两张桌子,Catch和Members。这是钓鱼俱乐部的网站。 我想列出名单,重量,Spiecies。但只有每个spiecies的最重量,如rekord列表。这两个表看起来像这样。
成员:
- MEMBERID
- 姓
- Secondname
捕捉:
- MEMBERID(FK)
- Spiecies
- 重量
这只显示名称和重量,我无法显示Spiecies。
SELECT
CONCAT(Firstname, ' ' ,Secondname) AS 'Name',
Allcatch.Rekord
FROM Members
JOIN
(SELECT
MAX(Weight) AS 'Rekord', MemberID
FROM Catch
GROUP BY MemberID) AS Allcatch
ON Allcatch.MemberID = Members.MemberID;
-- ORDER BY Allcatch.Weight DESC
答案 0 :(得分:0)
试试这个:
popSize = 350
答案 1 :(得分:0)
我使用了关于oracle
语法的row_number()函数构建了以下查询。
SELECT
Firstname||Secondname AS 'Name',
Allcatch.Rekord,
Allcatch.Spiecies
From Members
JOIN
(SELECT
Weight, MemberID, Spiecies,row_number() over (partition by MemberID order by Weight desc) as rn FROM Catch) AS Allcatch
ON Allcatch.MemberID = Members.MemberID
where Allcatch.rn = 1;