0% found this document useful (0 votes)
28 views

Informatics Practices Class 12 SQL

Sql question and answers

Uploaded by

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

Informatics Practices Class 12 SQL

Sql question and answers

Uploaded by

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

Informatics Practices Class 12

Important Questions SQL Functions


Question 1.
Write the output of the following SQL queries:
(i) SELECT RIGHT (‘software’, 2);
(ii) SELECT INSTR (‘twelve’, lV);
(iii) SELECT DAYOFMONTH (‘2014-03-01’);
(iv) SELECT (76.987,2); (All India 2014C)
Answer:
(i) re
(ii) 45
(iii) 01
(iv) 76.99

Question 2.
There is a column Salary in a Table EMPLOYEE. The following two statements are giving
different outputs. What may be the possible reason? (Delhi2013)

SELECT COUNT(*) FROM EMPLOYEE;


SELECT C0UNT(Salary) FROM EMPLOYEE;
Answer:

SELECT COUNT (*)


FROM EMPLOYEE:
This statement returns the number of records in the table.

SELECT COUNT(Salary)
FROM EMPLOYEE;
This statement returns the number of values (NULL values will not be counted) of the
specified column.

Question 3.
A table FLIGHT has 4 rows and 2 columns and another table AIRHOSTESS has rows and 4
columns. How
many rows and columns will be there if we obtain the cartesian product of these two
tables? (Delhi 2012)
Answer:
Total number of rows will be 12 and total number of columns will be 6.

Question 4.
What is the purpose of GROUP BY clause in MySQL? How is it different from ORDER BY
clause? (Delhi 2012; All India 2012)
Answer:
The GROUP BY clause can be used to combine all those records that have identical value
in a particular field or a group of fields. Whereas, ORDER BY clause is used to display the
records either in ascending or descending order based on a particular field. For ascending
order ASC is used and for descending order, DESC is used. The default order is ascending
order.

Question 5.
Shanya Khanna is using a table EMPLOYEE. It has the following columns:

Admno, Name, Agg, Stream [column Agg contains Aggregate marks]


She wants to display highest Agg obtained in each Stream.
She wrote the following statement:

SELECT Stream, MAX(Agg) FROM EMPLOYEE;


But she did not get the desired result. Rewrite the above query with necessary changes to
help her get the desired output.
Answer:

SELECT Stream, MAX(Agg)


FROM EMPLOYEE
GROUP BY Stream;

Question 6.
Consider the following table named SBOP with details of account holders. Write
commands of MySql for (i) to (iv) and output for (v) to (vii).
TABLE SBOP

(i) To display Accountno, Name and DateOfopen of account holders having transactions
more than 8.
(ii) To display all information of account holders whose transaction value is not
mentioned.
(iii) To add another column Address with datatype and size as VARCHAR(25).
(iv) To display the month day with reference to DateOfopen for all the account holders.
(Delhi2014)
(v) SELECT COUNT (*) FROM SBOP;
(vi) SELECT Name, Balance FROM SBOP WHERE Name LIKE “%i”;
(vii) SELECT ROUND (Balance,-3) FROM SBOP
WHERE Accountno="SB-5” ;
Answer:

(i) SELECT Account no, Name, DateOfopen FROM SBOP


WHERE Transaction > 8:
(ii) SELECT * FROM SBOP
WHERE Transaction IS NULL;
(iii) ALTER TABLE SBOP
ADD Address VARCHAR(25);
(iv) SELECT DAY0FM0NTH(DateOfopen), Name
FROM SBOP:
Question 7.
Question 8.
Question 9.
Question 10.

You might also like