stem
Discord ID: 387059792432201729
414 total messages. Viewing 100 per page.
Prev |
Page 5/5
it's just SQL
oh ya I forgot to tag <@&435155896780324864>
I ended up writing my own solution like this
```SQL
SELECT BOOKS.Title, BOOKS.Category, BOOKS.Cost
FROM BOOKS, (SELECT BOOKS.Category, AVG(BOOKS.Cost) AverageCost
FROM BOOKS
GROUP BY BOOKS.Category) AverageCosts
WHERE BOOKS.Category = AverageCosts.Category
AND BOOKS.Cost < AverageCosts.AverageCost
```
idk if the first one is better
mine feels less convoluted
@Jacob I agree yours is less convoluted that the first one, but I would do
```sql
SELECT Title, Category, Cost FROM
(
BOOKS
INNER JOIN
(
SELECT Category, AVG(Cost) as avg_cost FROM
BOOKS GROUP BY Category
)
)
WHERE Cost < avg_cost
```
haha wow that's a lot less
I think our teacher wants us to get practice with subqueries on this assignment, though
@Jacob well the avg cost part is calculated with a subquery
oh that's right
I don't think we officially learned to do subqueries in the JOIN clause yet
but that looks like a better solution for the future, thanks
414 total messages. Viewing 100 per page.
Prev |
Page 5/5