Screen Link:
Hey all,
Bit stuck on this question.
My Code:
DROP VIEW IF EXISTS chinook.customer_gt_90_dollars;
CREATE VIEW chinook.customer_gt_90_dollars AS
SELECT * FROM chinook.customer
WHERE (SELECT SUM(total) > 90
FROM invoice);
SELECT * FROM chinook.customer_gt_90_dollars;
What actually happened: I ended up with a 59 rows, instead of 18 (as the provided answer gets).
Apparently what I am supposed to do is:
CREATE VIEW chinook.customer_gt_90_dollars AS
SELECT
customer.*
FROM chinook.invoice AS i
INNER JOIN chinook.customer ON i.customer_id = customer.customer_id
GROUP BY 1
HAVING SUM(i.total) > 90;
Now, I totally understand that the above will provide the correct result. My first thought was to actually do an inner join as above, butt I am confused as to how my initial attempt didn’t provide a shortcut?
Could someone please explain this for me?
Many thanks!