0% found this document useful (0 votes)
82 views8 pages

Worksheet 19 Ans

Uploaded by

skhushbir247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views8 pages

Worksheet 19 Ans

Uploaded by

skhushbir247
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

IP /CS - My SQL Worksheet-19

Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
[2 marks questions] Q.NO. 24 - 33

1) State any two differences between single row functions and multiple row functions.

OR

What is the difference between the order by and group by clause when used along with the select
statement. Explain with an example.

Ans:- Differences between single row functions and multiple row functions. (i) Single row functions work on
one row only whereas multiple row functions group rows (ii) Single row functions return one output
per row whereas multiple row functions return only one output for a specified group of rows.

OR The order by clause is used to show the contents of a table/relation in a sorted manner with
respect to the column mentioned after the order by clause. The contents of the column can be
arranged in ascending or descending order.

The group by clause is used to group rows in a given column and then apply an aggregate function eg
max(), min() etc on the entire group. (any other relevant answer)

Single row v/s Multiple row functions 1 mark for each valid point

Group by v/s Order by 1 mark for correct explanation 1 mark for appropriate example

2) Consider the decimal number x with value 8459.2654. Write commands in SQL to: i. round it off to a
whole number ii. round it to 2 places before the decimal.

Ans:- i. select round(8459.2654);


ii. select round(8459.2654,-2);

1 mark each for correct answer of part (i) , (ii)

3) Anjali writes the following commands with respect to a table employee having fields, empno,
name, department, commission.

Command1 : Select count(*) from employee;


IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
Command2: Select count(commission) from employee;

She gets the output as 4 for the first command but gets an output 3 for the second command.
Explain the output with justification.

Ans:- This is because the column commission contains a NULL value and the aggregate functions do not
take into account NULL values. Thus Command1 returns the total number of records in the table
whereas Command2 returns the total number of non NULL values in the column commission.

4) Consider the following SQL string: “Preoccupied”

Write commands to display:

a. “occupied” b. “cup”

OR

Considering the same string “Preoccupied” Write SQL commands to display:

a. the position of the substring ‘cup’ in the string “Preoccupied” b. the first 4 letters of the string

Ans:- a. select substr("Preoccupied", 4);

or

select substring("Preoccupied", 4);

or

select mid("Preoccupied",4);

or
IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
select right(("Preoccupied"”, 8);

b. select substr("Preoccupied" ,6,3);

or

select substring("Preoccupied", 6,3);

or

select mid(("Preoccupied" ,6,3);

OR

a. select instr 'Preoccupied' , ‘ 'cup'));

b. select left 'Preoccupied',4);

1 mark for each correct answer of part (a) , (b)

5) What is the difference between the where and Having clause when used along with
the select statement. Explain with an example.

OR

Explain the difference between Update and Alter command with help of an
example.

Ans Where clause is used to apply condition on individual rows and not supports aggregate function

While Having clause is used to apply condition on groups and it supports aggregate functions.

Eg: SELECT * FROM EMP WHERE SALARY > 50000;

Eg: SELECT * FROM EMP GROUP BY DEPTNO HAVING COUNT(*) > 2;


IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….

OR

UPDATE command is a part of DML command and used to update the data of rows of a table.

While ALTER command is a part of DDL command and used to change the structure of a table like
adding column, removing it or modifying the datatype of columns.

Eg: UPDATE EMP SET SALARY = 20000;

ALTER EMP ADD EMP_DOJ DATE;

6) Write the output of following queries:-

i. SELECT SUBSTR('Aakila', -3);


ii. SELECT LEFT(‘Toolbar’, 4);
Ans:- I. ‘ila’
II. ‘Tool’
7) Raghav writes the following commands with respect to a table Flight having

Fields FLCODE, START, DESTINATION, NO_STOPS.

Command1 : Select count(*) from FLIGHT;

Command2: Select count(DESTINATION) from FLIGHT;

He gets the output as 5 for the first command but gets an output 3 for the

second command. Explain the output with justification.

Ans:- This is because the column DESTINATION contains a NULL value and the aggregate functions do not
take into account NULL values. Thus Command1 returns the total number of records in the table
whereas Command2 returns the total number of non NULL values in the column DESTINATION.

8) Write the output for following queries:

i. select MOD(11,4) "Modulus", power(3,2) "Raised";


IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
ii. select CURDATE( )+10;
OR

i. select length('CORONA COVID-19');


ii. select lcase('COMputer Science');

Ans:- i. Modulus Raised

-------------- ----------

3 9

ii. currentdate + 10 days aftward date will come

or

i. 15

ii. ‘computer science’

9) Consider the decimal number x with value 7459.3654. Write commands in SQL
to:
i) round it off to a whole number
ii) round it to 2 places before the decimal.

Ans:- (i) select round(7459.3654, 0)


(ii) select round(7459.3654, -2)

10) Shailly writes the following commands with respect to a table Employee
having fields, empno, name, department, commission.
Command1 : SELECT COUNT(*) FROM EMPLOYEE;
Command2 : SELECT COUNT(COMMISSION) FROM EMPLOYEE;

She gets the output as 7 for the first command but gets an output 5 for the
second command. Explain the output with justification.
IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
Ans:- This is because the column commission contains a NULL value and the aggregate
functions do not take into account NULL values. Thus Command1 returns the total
number of records in the table whereas Command2 returns the total number of non
NULL values in the column commission.

11) Consider the following SQL string: “SELFMOTIVATION”. Write commands to


display:
a. “MOTIVATION”
b. “MOT”

OR

Considering the same string “SELFMOTIVATION”. Write SQL commands to


display:
a. the position of the substring ‘MOTIV’ in the string “SELFMOTIVATION”
b. the last 6 letters of the string

Ans:- a. select substr(“SELFMOTIVATION”, 5)


b. select substr(“SELFMOTIVATION”, 5, 3)

OR

a. select instr(“SELFMOTIVATION”, “MOTIV”)


b. select right(“SELFMOTIVATION”, 6)

(student may use other functions like – substring/ mid/ right .. etc

12) State any two differences between Update and alter commands.

OR

What is datatype? What are the main objectives of datatypes?

Ans:- Data types are mean to identify the type of data and its associated functions.

The main objectives of datatypes is to clarify the type of data a variable can store and which
operations can be performed on it.

13) Consider the decimal number n with value 278.6975. Write commands in SQL :

i. That gives output 279


ii. That gives output 280
IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….

Ans:- i) select round(278.6975);

(ii) select round(278.6975,-1);

or some other queries that produces same results.

1 mark each for correct answer of part (i) , (ii)

14) (i) Consider a table “Employee” that have fields - empno, name, department, salary.

Based on the above table “Employee”, Manvendra has entered the following SQL command:

SELECT * FROM Employee where Salary = NULL;

But the Query is not executing successfully. What do you suggest to him in order to execute this
query i.e. write the correct query.

(ii) Write a SQL query to display the details of those employees whose Salary column has some
values.

Ans:- (i) select * from Employee where Salary is NULL;

(ii) select * from Employee where Salary is not NULL;

1 mark each for correct answer of part (i) , (ii)

15) Consider the following SQL string: “Master Planner”.

Write commands to display:

a. “Master”

b. “Plan”

OR

Considering the same string “Master Planner”.


IP /CS - My SQL Worksheet-19
Question Bank
Answers
https://unacademy.com/@LovejeetArora
Chalo Sath Mil Kar kre Shuru….
Write SQL commands to display:

a. the position of the substring ‘Plan’ in the string “Master Planner”

b. the Last 4 letters of the string

Ans:- a. select substr("Master Planner",1,6);

b. select substr("Master Planner",8,4); or some other queries that produces same results.

1 mark each for correct answer of part (i) , (ii)

OR

a. select instr("Master Planner","Plan");

b. select right("Master Planner",4); or some other queries that produces same results.

1 mark each for correct answer of part (i) , (ii)

You might also like