在 BigQuery 中分组时无法使用顺序

Can't use order when grouped by in BigQuery

我想按 FECHA_COMPRA 分组,然后按同一字段排序。但是当我这样做时,我收到一条错误消息:

SELECT list expression references column FECHA_COMPRA which is neither grouped nor aggregated at [28:13]

这是我正在使用的查询:

Select DATE(FECHA_COMPRA) as Date,TYPE,SUM(AMOUNT) AS Total, SUM(Quantity) as Qty FROM Test
GROUP BY DATE(FECHA_COMPRA)
Order by date(FECHA_COMPRA)

这也不起作用:

Select DATE(FECHA_COMPRA) as Date,TYPE,SUM(AMOUNT) AS Total, SUM(Quantity) as Qty FROM Test
GROUP BY DATE(FECHA_COMPRA)
Order by FECHA_COMPRA

怎么了? 谢谢!

改用下面的方法

select 
  date(fecha_compra) as date,
  type,
  sum(amount) as total, 
  sum(quantity) as qty 
from test
group by date, type
order by date