我在对象数据库中有一个嵌套表。现在我想要那个嵌套表中行数最多的行。
问题是,我没有对象数据库,但我必须学习一些考试的SQL语句。现在,我的查询如下所示:
SELECT o.Order_Number
FROM Order o, TABLE(o.Position) pos
GROUP BY o.Order_Number
HAVING COUNT (*) >= all
(SELECT COUNT(*)
FROM pos);
答案 0 :(得分:0)
对于大多数数据库,使用ANSI
SQL
,您可以使用RANK()
函数的小技巧
SELECT Order_Number, Order_Count FROM ( SELECT Order_Number, COUNT(1) Order_Count, RANK() OVER (ORDER BY COUNT(1) DESC) Ranking FROM [Position] GROUP BY Order_Number ) a WHERE Ranking = 1