简体   繁体   中英

Not a single-group function

SELECT s.*,count(numeromodule) as nbrmodule from session58 s natural join module15;

嗨,我收到此错误:不是单组函数

First, don't use 'natural join`. It uses the names of columns, and this can change over time, changing what the query does -- and causing it to suddenly break for no apparent reason. I'd have a softer spot in my heart if it used explicit foreign key relationships, but it doesn't.

Second, the problem is the s.* . Here is another way to do what you want:

select s.*,
       (select count(*) from module15 m where s.col1 = m.col1 . . . ) as nbrmodule
from session58 s;

I don't know what the join conditions are (another reason not to use natural join ).

Also, this will return 0 counts. If you do not want them, you can filter them out using a subquery, or this where clause:

where exists (select 1 from module15 m where s.col1 = m.col1 . . . )

you have to list the required fields in the group by section , eg

SELECT s.f1,s.f2,count(numeromodule) as nbrmodule 
from session58 s natural join module15 group by s.f1,s.f2;`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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