Worksheet 19 Ans
Worksheet 19 Ans
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.
3) Anjali writes the following commands with respect to a table employee having fields, empno,
name, department, commission.
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.
a. “occupied” b. “cup”
OR
a. the position of the substring ‘cup’ in the string “Preoccupied” b. the first 4 letters of the string
or
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);
or
or
OR
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.
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.
He gets the output as 5 for the first command but gets an output 3 for the
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.
-------------- ----------
3 9
or
i. 15
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.
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.
OR
OR
(student may use other functions like – substring/ mid/ right .. etc
12) State any two differences between Update and alter commands.
OR
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 :
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:
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.
a. “Master”
b. “Plan”
OR
b. select substr("Master Planner",8,4); or some other queries that produces same results.
OR
b. select right("Master Planner",4); or some other queries that produces same results.