[英]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.*
. 其次,问题是
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
). 我不知道
join
条件是什么(另一个不使用natural join
原因)。
Also, this will return 0
counts. 同样,这将返回
0
计数。 If you do not want them, you can filter them out using a subquery, or this where
clause: 如果不希望使用它们,则可以使用子查询或
where
子句将它们过滤掉:
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 您必须按部分列出
group by section
中的必填字段,例如
SELECT s.f1,s.f2,count(numeromodule) as nbrmodule
from session58 s natural join module15 group by s.f1,s.f2;`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.