我有这个简单的 SQL 查询,我试图为一个 uni 项目运行它。我在标题中收到错误,但是我运行了一个非常相似的查询,没有问题。
select booking.customer_id, booking_start_date
SUM(total_cost) sales
from booking
order by 2 desc
提前致谢。
你错过了一个,
after booking_start_date
。
尝试 -
select booking.customer_id,
booking_start_date,
SUM(total_cost) sales
from booking
GROUP BY booking.customer_id, booking_start_date
order by 2 desc
尝试以下..
select
booking.customer_id
, booking.start_date
, SUM(booking.total_cost) sales
from
booking
group by
booking.customer_id
, booking.start_date
order by
2 desc
这是您更新的查询。当您使用 COUNT、SUM、MIN、MAX 等聚合函数时,还应该使用 GROUP BY。
select booking.customer_id, booking_start_date
SUM(total_cost) sales
from booking group by booking.customer_id, booking_start_date
order by 2 desc