简体   繁体   English

Oracle SQL相关子查询:不是单组组函数

[英]Oracle SQL correlated subquery: not a single-group group function

I'm trying to count travels doctors went to and sum how much money tolls cost. 我试图计算医生去的旅行次数,并总结一下通行费要花多少钱。 I'm using ORACLE XE 11g and SQL Developer. 我正在使用ORACLE XE 11g和SQL Developer。 I tried to do that with correlated subquery in SELECT but I'm getting this message: 我试图用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 

This is query I talked about: 这是我谈论的查询:

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;

Counting worked just fine before I added subquery. 在添加子查询之前,计数工作正常。 Does anyone understand why I might be having this problem? 有谁知道我为什么会遇到这个问题?

您缺少GROUP BY列-personID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM