Skip to content
Question
Q.

Consider the following table : Table : SALESMAN

ScodeSnameAreaQtysoldDateofjoin
S001RaviNorth1202015-10-01
S002SandeepSouth1052012-08-01
S003SunilNULL682018-02-01
S004SubhWest2802010-04-01
S005AnkitEast902018-10-01
S006RamanNorthNULL2019-12-01

Predict the output for the following SQL queries : (i) SELECT MAX(Qtysold), MIN(Qtysold) FROM SALESMAN; (ii) SELECT COUNT (Area) FROM SALESMAN; (iii) SELECT LENGTH (Sname) FROM SALESMAN WHERE MONTH(Dateofjoin)=10; (iv) SELECT Sname FROM SALESMAN WHERE RIGHT(Scode,1)=5; OR Based on the given table SALESMAN write SQL queries to perform the following operations : (i) Count the total number of salesman. (ii) Display the maximum qtysold from each area. (iii) Display the average qtysold from each area where number of salesman is more than 1. (iv) Display all the records in ascending order of area.

CBSECBSE Class XII Board 2022Subjective· 4mImportance★★★★★
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

Part (a): outputs are (i) 280,68 (ii) 5 (iii) 4 and 5 (iv) Ankit.

Part (b): COUNT()=6; MAX per area with GROUP BY; AVG per area with HAVING COUNT()>1 (North=120); ORDER BY Area ASC.

Part (a)

The key is how SQL handles NULL. MAX, MIN, AVG and SUM skip NULLs; COUNT(column) counts only non-NULL values, while COUNT(*) counts every row.

(i) SELECT MAX(Qtysold), MIN(Qtysold) FROM SALESMAN; — from 120,105,68,280,90 (NULL skipped): max 280, min 68.

280 | 68

(ii) SELECT COUNT(Area) FROM SALESMAN; — five non-NULL areas (Sunil is NULL).

5

(iii) SELECT LENGTH(Sname) FROM SALESMAN WHERE MONTH(Dateofjoin)=10; — October joiners are Ravi (2015-10-01) and Ankit (2018-10-01).

4
5

(iv) SELECT Sname FROM SALESMAN WHERE RIGHT(Scode,1)=5; — only S005 ends in 5.

Ankit …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.