clear markdown compare help best fiddles feedback dbanow.uk
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. 2805483 fiddles created (40773 in the last week).

WITH A AS ( SELECT 'Dave' AS Names, 5 AS Sales, 'Shoes' AS Department UNION ALL SELECT 'mike', 6, 'Apparel' UNION ALL SELECT 'Dan', 7, 'Front End' ), B AS ( SELECT 'Dave' AS Names, 5 AS Sales, 'Shoes' AS Department UNION ALL SELECT 'mike', 12, 'Apparel' UNION ALL SELECT 'Dan', 7, 'Front End' UNION ALL SELECT 'Gregg', 23, 'Shoes' UNION ALL SELECT 'Kim', 15, 'Front End' ) SELECT SUM(CASE WHEN src = 'A' THEN sales ELSE 0 END) AS "A Sales Sum", SUM(CASE WHEN src = 'B' THEN sales ELSE 0 END) AS "B Sales Sum" FROM ( SELECT sales, 'A' AS src FROM A WHERE Names NOT IN ('Gregg', 'Kim') UNION ALL SELECT sales, 'B' FROM B WHERE Names NOT IN ('Gregg', 'Kim') ) t;
A Sales Sum B Sales Sum
18 24
 hidden batch(es)