1

How do I insert data into a table that I created using a case expression?

Tutorial i am reading

Im trying to populate the table only with the high popularity movie categories.

INSERT INTO category_summary (most_popular)
 SELECT category_name, rental_duration,
 CASE
 WHEN rental_duration <= 3
 THEN 'Low Popularity'
 WHEN rental_duration >= 4
 AND rental_duration < 6 THEN 'Medium Popularity'
 WHEN rental_duration >= 6 THEN 'High Popularity'
 END popularity
 FROM category_description
 WHERE popularity = 'High Popularity'
 ORDER BY category_name;


    
ERROR:  column "popularity" does not exist
LINE 11:  WHERE popularity = 'High Popularity'
Stack Ty
  • 51
  • 7
  • 1
    Note that you'll hit the next error once you solved the alias problem: your `insert` only specifies **one** target column, but your SELECT returns **three** –  Jan 31 '22 at 18:59
  • As @a_horse_with_no_name says: you will run into another problem after we help you with this question. How did you create the category_summary table? Maybe we give you some extra tips. – VvdL Jan 31 '22 at 19:03
  • I just used a create_table statement – Stack Ty Jan 31 '22 at 19:11

0 Answers0