(a) Given the following tables:
Table: STUDENTS
| S_ID | NAME | AGE | CITY |
|---|---|---|---|
| 1 | Rahul | 20 | Delhi |
| 2 | Priya | 22 | Mumbai |
| 3 | David | 21 | Delhi |
| 4 | Neha | 23 | Bengaluru |
| 5 | Khurshid | 22 | Delhi |
Table: GRADES
| S_ID | SUBJECT | GRADE |
|---|---|---|
| 1 | Math | A |
| 2 | English | B |
| 3 | Math | C |
| 4 | English | A |
| 5 | Math | B |
Write SQL queries for the following:
- To display the number of students from each city.
- To find the average age of all students.
- To list the names of students and their grades. OR
(b) Consider the following tables:
Table 1: PRODUCTS This table stores the basic details of the products available in a shop.
| PID | PName | Category |
|---|---|---|
| 201 | Laptop | Electronics |
| 202 | Chair | Furniture |
| 203 | Desk | Furniture |
| 204 | Smartphone | NULL |
| 205 | Tablet | Electronics |
Table 2: SALES This table records the number of units sold for each product.
| SaleID | PID | UnitsSold |
|---|---|---|
| 301 | 201 | 50 |
| 302 | 202 | 100 |
| 303 | 203 | 60 |
| 304 | 204 | 80 |
| 305 | 205 | 70 |
Write SQL queries for the following:
- To delete those records from table SALES whose UnitsSold is less than 80.
- To display names of all products whose category is not known.
- To display the product names along with their corresponding units sold.
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): COUNT(*) GROUP BY CITY (Delhi 3, Mumbai 1, Bengaluru 1); AVG(AGE)=21.6; equi-join on S_ID for names+grades.
Part (b): DELETE FROM SALES WHERE UnitsSold<80 (removes 3 rows); WHERE Category IS NULL → Smartphone; equi-join on PID for names+units sold.
Part (a) — STUDENTS and GRADES
(i) Students per city. Group by CITY and count.
SELECT CITY, COUNT(*) FROM STUDENTS GROUP BY CITY;
CITY COUNT(*)
Delhi 3
Mumbai 1
Bengaluru 1
(ii) Average age. A single aggregate over all rows.
SELECT AVG(AGE) FROM STUDENTS;
(20+22+21+23+22)=108, /5 = 21.6:
AVG(AGE)
21.6
(iii) Names and grades. The data lives in two tables linked by S_ID, so join them.
SELECT S.NAME, G.GRADE
FROM STUDENTS S, GRADES G
WHERE S.S_ID = G.S_ID;
NAME GRADE
Rahul A
Priya B
David C
Neha A
Khurshid B …
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.