Kodewick
Start learning →
Basic←→0 / 70

How many good ones

#057BasicCASEAggregates5 min

The cinema wants two numbers in one row: how many movies have a rating of 7 or more, and how many are below 7. The first column is written; add the second.

The tables
movies
idtitlegenreminutesrating
1Robot Summerfamily958
2Dark Lakehorror1106
3Space Palsfamily887
4The Long Roaddrama1429
5Laugh Trackcomedy1015
6Snow Daycomedy927
6 rows
tickets
idmovie_iddayseatsprice
11Fri240
21Sat480
32Fri125
43Sat354
54Sun260
61Sun120
75Sat236
83Sun590
8 rows
query.sql
SELECT
  SUM(CASE WHEN rating >= 7 THEN 1 ELSE 0 END)
  -- your code here: a comma, then another SUM(CASE …) that counts rating < 7
FROM movies;
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.