Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
19 views

SQL Revision IP

Sql revision.pdf, class 12 revision series by scribd information practices most recommend question

Uploaded by

shreyanshi1718
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

SQL Revision IP

Sql revision.pdf, class 12 revision series by scribd information practices most recommend question

Uploaded by

shreyanshi1718
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

SQL REVISION

1. ‘Employee’ table has a column named ‘CITY’ that stores city in which each employee resides. Write SQL query
to display details of all rows except those rows that have CITY as ‘DELHI’ or ‘MUMBAI’ or ‘CHANDIGARH’.

2. Abhay wants to know the number of students who took the test. He writes the following SQL statement to
count STUDENTID without duplicates. However, the statement is not correct. Rewrite the correct
statement.
SELECT DISTINCT (COUNT STUDENTID) FROM RESULTS;
SELECT COUNT (DISTINCT STUDENTID) FROM RESULTS;
3. Aman has used the following SQL command to create a table ‘stu’: [CBSE 2019]
CREATE TABLE stu
(
id INTEGER,
name VARCHAR(100)
);
Then,Aman enters the following SQL statements to enter 3 rows:
INSERT INTO stu VALUES(1,"abc");
INSERT INTO stu VALUES(2,"abc");
INSERT INTO stu VALUES(3,"bcd");
Write the output that will be produced by the following SQL statement :
SELECT name, Count(*)
FROM stu
GROUP BY name;

4. Table student has the columns RNO and SCORE. It has 3 rows in it. Following two SQL
statements were entered that produced the output (AVG(SCORE) as 45 and
COUNT(SCORE) as 2):
(i) AVG(SCORE)
(ii)COUNT(SCORE )
Data in SCORE column is same in two rows. What data is present in the SCORE
column in the three rows ?
5. Consider the following table ‘Transporter’ that stores the order details about items to be transported. Write
SQL commands for the statements (i) to (viii) and write output for SQL queries (ix) and (x).
i) To display names of drivers and destination city where TELEVISION is being transported.
Ans. SELECT DRIVERNAME, DESTINATION FROM TRANSPORTER WHERE ITEM="TELEVISION";
ii) To display driver names and destinations where destination is not MUMBAI.
Ans. SELECT DRIVERNAME, DESTINATION
FROM TRANSPORTER
WHERE DESTINATION <> "MUMBAI";
OR
SELECT DRIVERNAME, DESTINATION
FROM TRANSPORTER WHERE DESTINATION != "MUMBAI";
OR
SELECT DRIVERNAME, DESTINATION
FROM TRANSPORTER
WHERE DESTINATION NOT IN ("MUMBAI");
OR
SELECT DRIVERNAME, DESTINATION
FROM TRANSPORTER
WHERE NOT DESTINATION = "MUMBAI";
iii) To display the names of destination cities where items are being transported.There should be no
duplicate values.
Ans. SELECT DISTINCT(DESTINATION) FROM TRANSPORTER;
iv) To display details of rows that have some value in DRIVERGRADE column.
Ans. SELECT * FROM TRANSPORTER WHERE DRIVERGRADE IS NOT NULL;
v) To display names of drivers, names of items and travel dates for those items that are being transported
on or before 1st April 2019.
Ans. SELECT DRIVERNAME, ITEM, TRAVELDATE FROM TRANSPORTER
WHERE TRAVELDATE <= "2019-04-01";
vi) To display the number of drivers who have ‘MOHAN’ anywhere in their names.
Ans. SELECT COUNT(DRIVERNAME)
FROM TRANSPORTER
WHERE DRIVERNAME LIKE "%MOHAN%" ;
vii) To display the names of drivers, item names and travel dates in alphabetic (ascending) order of driver
names.
Ans. SELECT DRIVERNAME, ITEM, TRAVELDATE FROM TRANSPORTER ORDER BY
DRIVERNAME;
viii) To display names of drivers whose names are three characters long
Ans. SELECT DRIVERNAME FROM TRANSPORTER WHERE DRIVERNAME LIKE "_ _ _";
OR
SELECT DRIVERNAME FROM TRANSPORTER WHERE LENGTH(DRIVERNAME) = 3 ;
ix) SELECT ITEM,COUNT(*) FROM TRANSPORTER GROUP BY ITEM HAVING COUNT(*) > 1;

x) SELECT MAX(TRAVELDATE) FROM TRANSPORTER WHERE DRIVERGRADE=’A’;


Ans. MAX(TRAVELDATE)
2019-04-19
6. Consider the following tables PARTICIPANT and ACTIVITY and answer the questions
that follow:
i) When the table “PARTICIPANT” was first created, the column ‘NAME’ was planned as the
Primary key by the Programmer. Later a field ADMNO had to be set up as Primary key.
Explain the reason.
Ans. NAME column has duplicate values ,cannot be considered as Primary key, therefore
Admno is to be considered as Primary Key.
ii) Identify data type and size to be used for column ACTIVITYCODE in table ACTIVITY.
Ans. Data type : CHAR / VARCHAR
Size : 4
iii) With reference to the above given tables (in Q6 b), write commands in SQL for (i) to (ii)
Ans. SELECT ACTIVITYCODE, COUNT(*) FROM PARTICIPANT GROUP BY ACTIVITYCODE;
iv) To display Names of Participants , Activity Code, Activity Name in alphabetic ascending
order of names of participants.
Ans. SELECT P.NAME, P.ACTIVITYCODE, A.ACTIVITYNAME
FORM PARTICIPANT P, ACTIVITY A
WHERE P.ACTIVITYCODE = A.ACTIVITYCODE
ORDER BY NAME ;
7. Find the output of the following SQL Queries :
(i) SELECT ROUND (7658.345, 2);
(ii) SELECT MOD (ROUND (13·9, 0), 3);
Ans. (i) 7658·35
(ii) 2
8. Srikanth created the following table STUDENT in his database. [CBSE 2022]
Table : STUDENT

He now wants to count number of students in each class where the number of students is
more than 3. He has executed the following query :
SELECT MAX (Marks) FROM STUDENT WHERE COUNT (*) > 3 GROUP
BY Class;
But, he got an error. Identify the error(s) and rewrite the query. Also underline the
correction(s) done.
Ans. SELECT CLASS, COUNT(*) FROM STUDENT
GROUP BY CLASS HAVING COUNT (*) > 3;
OR
SELECT COUNT(*) FROM STUDENT
GROUP BY CLASS HAVING COUNT (*) > 3;

NOTE: COUNT() to be accepted with any column name in place of *


9. Ms Mohini is working in a school and stores the details of all students in a table SCHOOLDATA.
TABLE : SCHOOLDATA

1. Write SQL statements from the above given table to:


(i) To remove leading spaces from the column name;
(ii) Display the names of students who were born on Sunday.
Ans. (i) SELECT LTRIM (Name) FROM SCHOOLDATA;
(ii) SELECT NAME FROM SCHOOLDATA WHERE DAYNAME (DoB)="Sunday";
2. Predict the output of the following SQL queries from the above table :SCHOOLDATA
(i) SELECT MAX (Percent) FROM SCHOOLDATA;
(ii) SELECT LEFT (Gender, 1), Name FROM SCHOOLDATA WHERE YEAR (Dob) =2005;
Ans. (i) 91
(ii) F Swapnil Pant
M Rahil Arora
10. Keshav has written the following query to find out the sum of bonus earned by the
employees of WEST zone :

SELECT zone, TOTAL (bonus) FROM employee HAVING zone = 'WEST';


But he got an error. Identify the errors and rewrite the query by underlining the correction(s) done.

Ans. SELECT zone, SUM(bonus) FROM employee WHERE Zone = 'WEST';


OR
SELECT SUM(bonus) FROM employee WHERE Zone = 'WEST';
OR
SELECT zone, SUM(bonus) FROM employee GROUP BY zone HAVING Zone = 'WEST';

You might also like