clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 635473 fiddles created (13106 in the last week).

WITH tableA (genre, collection) AS ( VALUES ('horror', 20), ('action', 50), ('rom-com', 30), ('sci-fi', 90) ), tableB (MovieId, genre, performance) AS ( VALUES (1, 'sci-fi' , 'Hit'), (2, 'rom-com', 'Hit'), (3, 'sci-fi' , 'Flop'), (4, 'rom-com', 'Hit'), (5, 'rom-com', 'Hit'), (6, 'horror' , 'Flop'), (7, 'horror' , 'Flop'), (8, 'sci-fi' , 'Hit'), (9, 'rom-com', 'Hit') ) SELECT tableA.genre, COUNT(tableB.genre) hit_movies, SUM(CASE WHEN tableB.genre IS NULL THEN 0 ELSE tableA.collection END) total_collection FROM tableA LEFT JOIN tableB ON tableA.genre = tableB.genre AND tableB.performance = 'Hit' GROUP BY tableA.genre ORDER BY total_collection
genre hit_movies total_collection
horror 0 0
action 0 0
rom-com 4 120
sci-fi 2 180
 hidden batch(es)