Computer Science

Consider the tables PRODUCT and BRAND given below:

Table: PRODUCT

PCodePNameUPriceRatingBID
P01Shampoo1206M03
P02Toothpaste548M02
P03Soap257M03
P04Toothpaste654M04
P05Soap385M05
P06Shampoo2456M05

Table: BRAND

BIDBName
M02Dant Kanti
M03Medimix
M04Pepsodent
M05Dove

Write SQL queries for the following:

(i) Display product name and brand name from the tables PRODUCT and BRAND.

(ii) Display the structure of the table PRODUCT.

(iii) Display the average rating of Medimix and Dove brands.

(iv) Display the name, price, and rating of products in descending order of rating.

SQL Joins & Grouping

4 Likes

Answer

(i)

SELECT PName, BName FROM PRODUCT P, 
BRAND B WHERE P.BID = B.BID;

(ii)

DESC PRODUCT;

(iii)

SELECT BName, AVG(Rating) FROM PRODUCT 
P, BRAND B
WHERE P.BID = B.BID
GROUP BY BName
HAVING BName = 'Medimix' OR 
BName = 'Dove';

(iv)

SELECT PName, UPrice, Rating
FROM PRODUCT
ORDER BY Rating DESC;

Answered By

4 Likes


Related Questions