Professional Documents
Culture Documents
Assignment Answer
Assignment Answer
Overview:
There are 4 CSVs present in the folder which contain a representative
data of 4 different tables in PSQL.
1. `category_id` in the `listingdata` table is ForeignKey to
`category` table on the `id` column
2. `brand_id` in the `listingdata` table is ForeignKey to `brands`
table on the `id` column
3. `listing_id` in the `listinghistory` table is ForeignKey to
`listingdata` table on the `id` column
Problems:
Ans 2:
SELECT c.name, AVG(lh.selling_price) AS avg_price
FROM brands b
INNER JOIN listingdata ld ON b.id = ld.brand_id
INNER JOIN category c ON ld.category_id = c.id
INNER JOIN listinghistory lh ON lh.listing_id = ld.id
WHERE b.name = 'JOCKEY'
GROUP BY c.name;
Ans 3: