Class - 12 CBSE Computer Science Important Output Questions 2025
Predict the output of the following queries based on the table CAR_SALES given below :
NUMBER | SEGMENT | FUEL | QT1 | QT2 |
---|---|---|---|---|
1 | Compact HatchBack | Petrol | 56000 | 70000 |
2 | Compact HatchBack | Diesel | 34000 | 40000 |
3 | MUV | Petrol | 33000 | 35000 |
4 | MUV | Diesel | 14000 | 15000 |
5 | SUV | Petrol | 27000 | 54000 |
6 | SUV | Diesel | 18000 | 30000 |
7 | Sedan | Petrol | 8000 | 10000 |
8 | Sedan | Diesel | 1000 | 5000 |
(i) SELECT LEFT(SEGMENT, 2) FROM CAR_SALES WHERE FUEL= "PETROL";
(ii) SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV";
(iii) SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
SQL Queries
5 Likes
Answer
(i) SELECT LEFT(SEGMENT, 2) FROM CAR_SALES WHERE FUEL= "PETROL";
+------------------+
| LEFT(SEGMENT, 2) |
+------------------+
| Co |
| MU |
| SU |
| Se |
+------------------+
Working
In the query SELECT LEFT(SEGMENT, 2) FROM CAR_SALES WHERE FUEL= "PETROL";
, the function LEFT(SEGMENT, 2)
takes the leftmost characters of each SEGMENT value, starting from the first character, and returns two characters. The WHERE FUEL = 'PETROL'
clause filters the rows to include only those with 'PETROL' as the fuel type.
(ii) SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV";
+------------+
| AVG SALE |
+------------+
| 13500.0000 |
| 6000.0000 |
+------------+
Working
The SQL query SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV";
calculates the average sale for the "SUV" segment in the CAR_SALES table. It does this by subtracting the first quarter sales (QT1) from the second quarter sales (QT2) for each record in the "SUV" segment and then dividing the result by 2. The alias "AVG SALE" is assigned to the computed value.
(iii) SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
+----------+
| TOT SALE |
+----------+
| 67000 |
+----------+
Working
The query SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
calculates the total sales for the "DIESEL" fuel type in the CAR_SALES table. It does this by summing up the values in the QT1 column for rows where the FUEL column is equal to "DIESEL". The alias "TOT SALE" is assigned to the computed sum.
Answered By
1 Like