ORA-00979 不是按表达式分组?
ORA-00979 Not a group by expression?
我有以下抛出异常的代码
Ora-00979: Not a group by expression.
即使我删除了 group by
子句,它仍然会报错
ORA-00937: not a single-group group function.
我是这个领域的新手,对连接等方面的知识还不够。如果有人能帮助我解决以下问题,我将不胜感激。
select sDateTime AS Sale_Date, SUM(Amount) AS Sale, SerName
FROM SALES natural join sales_Description natural join Services
where ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
and (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd')
SerName
列未包含在 GROUP BY
子句中。您必须将其包含在 GROUP BY
子句中或将其聚合(MAX
、MIN
等)。
尝试将您的查询更改为:
SELECT sDateTime AS Sale_Date, SUM(Amount) AS Sale, SerName
FROM SALES natural join sales_Description natural join Services
WHERE ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
AND (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd'), SerName
总之,不知道是不是你想要的结果
第一个错误not a group by
是由于以下-
GROUP BY to_char(sDateTime,'yyyy-MM-dd'),
.
您需要在 select
中使用相同的 to_char
或将 group by
更改为 sDateTime
。
第二次报错not a single-group group
错误是因为你删除了group by expression。您需要拥有 select list
的 columns
行,您是 aggregating
行。
尝试以下 -
SELECT to_char(sDateTime,'yyyy-MM-dd') AS Sale_Date,
SerName,
SUM(Amount) AS Sale
FROM SALES natural join sales_Description natural join Services
WHERE ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
AND (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd'), SerName
我有以下抛出异常的代码
Ora-00979: Not a group by expression.
即使我删除了 group by
子句,它仍然会报错
ORA-00937: not a single-group group function.
我是这个领域的新手,对连接等方面的知识还不够。如果有人能帮助我解决以下问题,我将不胜感激。
select sDateTime AS Sale_Date, SUM(Amount) AS Sale, SerName
FROM SALES natural join sales_Description natural join Services
where ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
and (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd')
SerName
列未包含在 GROUP BY
子句中。您必须将其包含在 GROUP BY
子句中或将其聚合(MAX
、MIN
等)。
尝试将您的查询更改为:
SELECT sDateTime AS Sale_Date, SUM(Amount) AS Sale, SerName
FROM SALES natural join sales_Description natural join Services
WHERE ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
AND (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd'), SerName
总之,不知道是不是你想要的结果
第一个错误not a group by
是由于以下-
GROUP BY to_char(sDateTime,'yyyy-MM-dd'),
.
您需要在 select
中使用相同的 to_char
或将 group by
更改为 sDateTime
。
第二次报错not a single-group group
错误是因为你删除了group by expression。您需要拥有 select list
的 columns
行,您是 aggregating
行。
尝试以下 -
SELECT to_char(sDateTime,'yyyy-MM-dd') AS Sale_Date,
SerName,
SUM(Amount) AS Sale
FROM SALES natural join sales_Description natural join Services
WHERE ((sDateTime >= to_date('2015-01-01','yyyy-MM-dd'))
AND (sDateTime <= to_date('2015-01-09','yyyy-MM-dd')))
GROUP BY to_char(sDateTime,'yyyy-MM-dd'), SerName