1

我有这个简单的 SQL 查询,我试图为一个 uni 项目运行它。我在标题中收到错误,但是我运行了一个非常相似的查询,没有问题。

select booking.customer_id, booking_start_date
   SUM(total_cost) sales
from booking
order by 2 desc 

提前致谢。

4

3 回答 3

5

你错过了一个, 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 
于 2012-12-11T00:33:10.223 回答
0

尝试以下..

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 
于 2012-12-11T00:51:13.110 回答
0

这是您更新的查询。当您使用 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 
于 2012-12-11T09:42:16.617 回答