gpt4 book ai didi

mysql - #1111 - 在 mysql 中无效使用组函数

转载 作者:行者123 更新时间:2023-11-29 03:01:36 24 4
gpt4 key购买 nike

我有一个包含字段的表 M_DAILY

PS_DATE date,
tp int,
ep int,
mp int,

并且有一个用户定义的函数 nvl(x,y) 的工作版本,如果 x 不为 null 则返回 x,如果 x 为 null 则返回 y

我的 MySQL 查询是-

select sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(tp,0) else 0 end))tp, sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(ep,0) else 0 end)) ep, sum(avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(mp,0) else 0 end)) mp
from M_DAILY
where PS_DATE >= date ('2005-01-01') and PS_DATE <= date ('2005-12-31')
group by PS_DATE;

出现以下错误

#1111 - Invalid use of group function in mysql

请帮忙。

最佳答案

SUM(), COUNT(), AVG(), MIN(), MAX(), etc. are aggregate functions that requires you to specify a GROUP BY, unless you're using them on every column in your SELECT-list.

删除Group By 子句

试试这个

SELECT SUM(tp),SUM(ep),SUM(mp) FROM
(
SELECT Avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(tp,0) else 0 end) tp,
Avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(ep,0) else 0 end) ep,
Avg(case date_format(PS_DATE,'%Y') when '2005' then nvl(mp,0) else 0 end) mp
FROM M_DAILY
WHERE PS_DATE >= date ('2005-01-01') and PS_DATE <= date ('2005-12-31');
) As T

关于mysql - #1111 - 在 mysql 中无效使用组函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22828569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com