oracle12c:SQL 错误: ORA-00979: 不是 GROUP BY 表达式

SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANYGROUP by COMPANY.STATE having COMPANY.NAME = BILLS.NAME;
我就不知道哪里错了,group by在select里面的字段必须有,但是全加上去了还是不行,何解?

having后面的东西换成where写吧,having我记得写的是组过滤的条件,我觉得你应该是要先连接查询,再分组,如果分组后还需要过滤就写having子句,如果不需要就不写having子句
SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY where COMPANY.NAME = BILLS.NAME
GROUP by COMPANY.STATE ;
温馨提示:内容为网友见解,仅供参考
第1个回答  2014-03-07
好吧,having 只能用于聚集函数。不能用于表连接。表连接用ON 关键字!
你的sql 应该是
SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY
COMPANY.NAME = BILLS.NAME GROUP by COMPANY.STATE追问

SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY

WHERE COMPANY.NAME = BILLS.NAME GROUP  BY COMPANY.STATE;

追答

where 改为 on

追问

追答

SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS JOIN COMPANY
COMPANY.NAME = BILLS.NAME GROUP by COMPANY.STATE

第2个回答  2014-03-07
SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY
where COMPANY.NAME = BILLS.NAME
GROUP by COMPANY.STATE ;本回答被网友采纳
第3个回答  2014-03-07
SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY
GROUP by BILLS.NAME, BILLS.AMOUNT having COMPANY.NAME = BILLS.NAME;追问

不对

oracle12c:SQL 错误: ORA-00979: 不是 GROUP BY 表达式
having后面的东西换成where写吧,having我记得写的是组过滤的条件,我觉得你应该是要先连接查询,再分组,如果分组后还需要过滤就写having子句,如果不需要就不写having子句 SELECT COMPANY.STATE, COUNT(BILLS.NAME), SUM(BILLS.AMOUNT) FROM BILLS, COMPANY where COMPANY.NAME = BILLS.NAME GROUP by ...

相似回答