This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TABLE: cats | |
id name age breed net_worth | |
---------- ---------- ---------- ------------- ---------- | |
1 Maru 3 Scottish Fold 1000000 | |
2 Hana 1 Tabby 21800 | |
3 Grumpy Cat 4 Persian 181600 | |
4 Lil\' Bub 2 Tortoiseshell 2000000 | |
=============================================================== | |
|| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT SUM(cats.net_worth) | |
FROM owners | |
INNER JOIN cats_owners | |
ON owners.id = cats_owners.owner_id | |
JOIN cats ON cats_owners.cat_id = cats.id | |
WHERE cats_owners.owner_id = 2; | |
# which will return the following | |
SUM(cats.net_worth) | |
------------------- |
NewerOlder