Advertisements
Advertisements
Question
Consider the tables PRODUCT and BRAND given below:
| Table: PRODUCT | ||||
| PCode | PName | UPrice | Rating | BID |
| P01 | Shampoo | 120 | 6 | M03 |
| P02 | Toothpaste | 54 | 8 | M02 |
| P03 | Soap | 25 | 7 | M03 |
| P04 | Toothpaste | 65 | 4 | M04 |
| P05 | Soap | 38 | 5 | M05 |
| P06 | Shampoo | 245 | 6 | M05 |
| Table: BRAND | |
| BID | BName |
| M02 | Dant Kanti |
| M03 | Medimix |
| M04 | Pepsodent |
| M05 | Dove |
Write SQL queries for the following:
- Display product name and brand name from the tables PRODUCT and BRAND.
- Display the structure of the table PRODUCT.
- Display the average rating of Medimix and Dove brands.
- Display the name, price, and rating of products in descending order of rating.
Short/Brief Note
Advertisements
Solution
- SELECT PName, BName FROM PRODUCT P, BRAND B WHERE P.BID = B.BID;
- DESC PRODUCT;
- SELECT BName, AVG(Rating) FROM PRODUCT P, BRAND B
WHERE P.BID = B.BID
GROUP BY BName
HAVING BName = 'Medimix' OR
BName = 'Dove'; - SELECT PName, UPrice, Rating
FROM PRODUCT
ORDER BY Rating DESC;
shaalaa.com
SQL for Data Query
Is there an error in this question or solution?
