Test Index

Structured Query Language (SQL) Get it on Google PlayDownload on the App Store CBSE Board Videos

© examsnet.com
Question : 51 of 58
Marks: +1, -0
(a) Consider the following tables – Student and Sport :
Table : Student
ADMNONAMECLASS
1100MEENAX
1101VANIXI
Table : Sport
ADMNOGAME
1100CRICKET
1103FOOTBALL
What will be the output of the following statement ? (1)
SELECT * FROM Student, Sport;
(b) Write the output of the queries (i) to (iv) based on the table, GARMENT given below : (2)
TABLE : GARMENT
GCODETYPEPRICEFCODEODR_DATE
G101EVENING GOWN850F032008-12-19
G102SLACKS750F022020-10-20
G103FROCK1000F012021-09-09
G104TULIP SKIRT1550F012021-08-10
G105BABY TOP1500F022020-03-31
G106FORMAL PANT1250F012019-01-06
(i) SELECT DISTINCT(COUNT(FCODE))FROM GARMENT;
(ii) SELECT FCODE, COUNT(*), MIN(PRICE) FROM GARMENT GROUP BY FCODE HAVING COUNT(*)>1;
(iii) SELECT TYPE FROM GARMENT WHERE ODR_DATE >'2021-02-01' AND PRICE <1500;
(iv) SELECT * FROM GARMENT WHERE TYPE LIKE 'F%';
[CBSE 2023 Compartment]
Solution:  
(a)
Two tables written after FROM without a join condition give their Cartesian product: every row of Student is joined with every row of Sport. Rows = 2 × 2 = 4, columns = 3 + 2 = 5.
ADMNONAMECLASSADMNOGAME
1100MEENAX1100CRICKET
1100MEENAX1103FOOTBALL
1101VANIXI1100CRICKET
1101VANIXI1103FOOTBALL
(b)
(i) COUNT(FCODE) counts all non-NULL FCODE values in the table, i.e. all 6 rows (it does not count different codes). It gives one value, 6, and DISTINCT on that single row leaves it unchanged.
DISTINCT(COUNT(FCODE))
6
Key point: To count the different codes (3) the query must be COUNT(DISTINCT FCODE); DISTINCT(COUNT(FCODE)) still gives 6.
(ii) Groups: F01 = G103, G104, G106 (3 rows, lowest price 1000); F02 = G102, G105 (2 rows, lowest price 750); F03 = G101 (1 row, removed by HAVING COUNT(*) > 1).
FCODECOUNT(*)MIN(PRICE)
F022750
F0131000
(iii) Orders after 2021-02-01 are G103 (2021-09-09, price 1000) and G104 (2021-08-10, price 1550); only G103 also has PRICE below 1500.
TYPE
FROCK
(iv) LIKE 'F%' selects types that begin with F.
GCODETYPEPRICEFCODEODR_DATE
G103FROCK1000F012021-09-09
G106FORMAL PANT1250F012019-01-06
© examsnet.com
Advertisements
Go to Question: