【发布时间】:2022-01-05 09:57:03
【问题描述】:
考虑下表:
TABLE PAPER // it contains IDs of scientific papers and IDs of the scientists who wrote them
╔═══════════╦═════════════╗
║ PaperID ║ ScientistID ║
╠═══════════╬═════════════╣
║ 10 ║ 1 ║
╠═══════════╬═════════════╣
║ 11 ║ 1 ║
╠═══════════╬═════════════╣
║ 12 ║ 2 ║
╠═══════════╬═════════════╣
║ 13 ║ 3 ║
╚═══════════╩═════════════╝
TABLE SCIENTISTS // it contains IDs of scientists and their names
╔═════════════╦════════════════╗
║ ScientistID ║ ScientistName ║
╠═════════════╬════════════════╣
║ 1 ║ Tikola Nesla ║
╠═════════════╬════════════════╣
║ 2 ║ Carie Murie ║
╠═════════════╬════════════════╣
║ 3 ║ Nsaac Iewton ║
╚═════════════╩════════════════╝
我正在寻找一个 SELECT 查询来打印科学家的姓名以及他们发表了多少次科学论文,所需的结果应该是这样的:
CountOfPapersPerScientist ScientistName
------------------------- -------------
2 Tikola Nesla
1 Carie Murie
1 Nsaac Iewton
我能够使用这个打印每个科学家的论文数量:
SELECT COUNT(PaperID) FROM PAPER GROUP BY ScientistID;
但这不起作用:
SELECT COUNT(PaperID), ScientistName FROM PAPER, SCIENTISTS WHERE SCIENTISTS.ScientistID=PAPER.ScientistID GROUP BY PAPER.ScientistID;
ERROR at line 1:
ORA-00979: not a GROUP BY expression
什么是“GROUP BY 表达式”,为什么我的查询不是一个?我可以使用什么替代查询?
【问题讨论】:
-
是oracle还是mysql?唯一相关的标签
-
你应该离开加入科学家表