1

I need to have results beyond 147 but when I execute my code workbench say me Error Code: 1054. Unknown column 'total_spend' in 'where clause'

SELECT
  customer_id,
  actor.first_name as first_name,
  actor.last_name as last_name,
  sum(amount) as total_spend
FROM payment
INNER JOIN actor
  ON customer_id = actor_id
where total_spend < 100
group by customer_id
order by total_spend desc;

Can you help me pls ?

Phil
  • 157,677
  • 23
  • 242
  • 245
JusRays
  • 13
  • 3

1 Answers1

1

You need a having clause, also you cannot use the column alias in where/having clause

SELECT
  customer_id,actor.first_name as first_name,
  actor.last_name as last_name,sum(amount) as total_spend
FROM payment INNER JOIN actor ON customer_id = actor_id
group by customer_id
having sum(amount)<100
order by total_spend desc
Fahmi
  • 37,315
  • 5
  • 22
  • 31