在这个简单的 group by error 中别名是导致错误的原因吗?

Is aliasing the cause of the error in this simple group by error?

我对 SQL 开发人员有点陌生,我收到错误“不是按表达式分组”

select cmp.company_name, sum( inv.total_price ), inv.invoice_date FROM companies cmp join invc_header inv on cmp.cmp_auto_key = inv.cmp_auto_key group by cmp.company_name

也许是别名的原因?我已经阅读了尽可能多的帖子,但找不到障碍。

杰夫

select CMP.COMPANY_NAME
     , sum(INV.TOTAL_PRICE)
     , INV.INVOICE_DATE
  from COMPANIES CMP
  join INVC_HEADER INV on CMP.CMP_AUTO_KEY = INV.CMP_AUTO_KEY
 group by CMP.COMPANY_NAME, inv.invoice_date;

您的第 3 列不是 'rollup',因此您还需要根据 INVOICE_DATE 进行分组...除非您想将其更改为 MIN() 或 AVG()。 ..