我对Oracle SQL脚本有疑问。我需要选择所有作者(登录)与大多数出版物。如果有更多登录具有相同数量的出版物,我需要全部选择它们。 list of publications looks like this:
我需要使用 MAX()功能..到目前为止,我尝试过这样的事情:
SELECT P.LOGIN, COUNT(*)
FROM PISE P
GROUP BY P.LOGIN, HAVING COUNT(*) >= MAX(PUBLICATIONS)
(
SELECT COUNT(*) AS PUBLICATIONS
FROM PISE P
GROUP BY P.LOGIN
);
导致ORA-00933:SQL命令未正确结束
或
SELECT P.LOGIN, COUNT(*) as PUBLICATIONS
FROM PISE P
GROUP BY P.LOGIN HAVING PUBLICATIONS >= MAX(PUBLICATIONS);
导致ORA-00904:"出版物":无效标识符
或
SELECT P.LOGIN, COUNT(*)
FROM PISE P
WHERE COUNT(*) IN (
SELECT MAX(COUNT(*))
FROM PISE
);
导致ORA-00934:此处不允许使用组功能。
This is the result I am looking for
(没有Jmeno和Prijmeni专栏)。
答案 0 :(得分:1)
使用“with clause”(版本11及以上版本):
with a as (select login, count(*) as cnt from p group by login),
b as (select max(cnt) as max_cnt from a)
select a.login, a.cnt from a, b where a.cnt = b.max_cnt
/