Using the chinook database available at:
https://github.com/lerocha/chinook-database

The following query should return 26 rows, instead I returns 15.


WITH GbC AS ( SELECT c.Country, c.CustomerId, SUM(i.total) spent
FROM Customer c
JOIN Invoice i
ON i.CustomerId = c.CustomerId
GROUP BY 1, 2),
MbC AS ( SELECT Country, MAX(spent) spent
FROM GbC GROUP BY 1)
SELECT outerr.*
FROM GbC outerr
WHERE outerr.spent =
(SELECT spent
FROM MbC WHERE Country = outerr.Country)
ORDER BY 1, 3 DESC


-- 

Edson Poderoso
_______________________________________________
sqlite-users mailing list
[email protected]
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to