SELECT
family_id,
MIN((city)) keep (DENSE_RANK FIRST ORDER BY COUNT (city) DESC)
FROM FAMILY_MEMBERS
GROUP BY family_id;
错误:ORA-00979:不是GROUP BY表达式 00979. 00000 - “不是GROUP BY表达式” *原因:
*行动: 行错误:116列:24
答案 0 :(得分:-1)
您不能将窗口函数(dense_rank())与GROUP BY一起使用。如果您需要同时执行这两项操作,则必须进行子选择。
编辑: 这是我的建议:
SELECT y.family_id, y.City
FROM
(SELECT x.family_id, x.City, x.Member_count,
row_number() OVER (PARTITION BY x.family_id ORDER BY x.Member_count DESC) rn
FROM
(SELECT family_id, City, COUNT(*) Member_count
FROM FAMILY_MEMBERS
GROUP BY family_id, City) x) y
WHERE y.rn = 1;