我试图计算医生去的旅行数,并计算通行费需要多少钱。我正在使用ORACLE XE 11g和SQL Developer。我尝试在SELECT中使用相关子查询来做到这一点,但我收到了这条消息:
ORA-00937: not a single-group group function
00937. 00000 - "not a single-group group function"
*Cause:
*Action:
Error at Line: 2 Column: 11
这是我谈到的问题:
SELECT person.name, person.surname, COUNT(DISTINCT travelID) AS numberoftravels,
(SELECT SUM(costs.cost) FROM costs
JOIN travel ON costs.travelID = travel.travelID
JOIN person ON travel.personID = person.personID
JOIN staff ON travel.personID = staff.staffID
WHERE stafftype = 'Doctor' AND costtype = 'tolls' and staff1.staffID = person.personID
) AS tollscost
FROM travel JOIN person ON person.personID = travel.personID
JOIN staff staff1 ON staff1.staffID = person.personID
WHERE stafftype = 'Doctor'
GROUP BY person.name, person.surname;
在添加子查询之前,计数工作正常。有谁知道我为什么会遇到这个问题?
答案 0 :(得分:0)
您缺少GROUP BY列 - personID