stem

Discord ID: 387059792432201729


414 total messages. Viewing 100 per page.
Prev | Page 5/5

2019-02-24 03:39:39 UTC

it's just SQL

2019-02-24 03:39:53 UTC

oh ya I forgot to tag <@&435155896780324864>

2019-02-24 04:08:38 UTC

I ended up writing my own solution like this

2019-02-24 04:09:39 UTC

```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
```

2019-02-24 04:09:57 UTC

idk if the first one is better

2019-02-24 04:10:12 UTC

mine feels less convoluted

2019-02-24 04:26:18 UTC

@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
```

2019-02-24 04:26:59 UTC

haha wow that's a lot less

2019-02-24 04:27:39 UTC

I think our teacher wants us to get practice with subqueries on this assignment, though

2019-02-24 04:28:27 UTC

@Jacob well the avg cost part is calculated with a subquery

2019-02-24 04:29:17 UTC

oh that's right

2019-02-24 04:29:49 UTC

I don't think we officially learned to do subqueries in the JOIN clause yet

2019-02-24 04:30:04 UTC

but that looks like a better solution for the future, thanks

414 total messages. Viewing 100 per page.
Prev | Page 5/5