'Can't use order when grouped by in BigQuery

I want to group by FECHA_COMPRA and then order by the same field. But when I do this, I get an error message:

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

This are the querys I'm using:

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)

This is also not working:

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

What is wrong? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source