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

ANSKEY SQL

The document provides a series of SQL questions and answers, covering various SQL functions and queries. It explains the differences between math and string functions, demonstrates how to use aggregate functions, and predicts outputs for specific SQL queries. Additionally, it addresses invalid data types and substring manipulations in SQL.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

ANSKEY SQL

The document provides a series of SQL questions and answers, covering various SQL functions and queries. It explains the differences between math and string functions, demonstrates how to use aggregate functions, and predicts outputs for specific SQL queries. Additionally, it addresses invalid data types and substring manipulations in SQL.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ANSKEY SQL

1. Which of the following SQL functions does not belong to the Math
functions category?

The correct answer is:


iii. LENGTH()
Explanation: LENGTH() is a string function, not a math function. The other
functions (POWER(), ROUND(), and MOD()) are all mathematical functions.

2. Raj, a Database Administrator, needs to display the average pay


of workers from those departments which have more than five
employees. Which of the following is a correct query to perform the
given task?

The correct answer is:


iv. SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT HAVING
COUNT(*) > 5;
Explanation: The HAVING clause is used to filter records based on an
aggregate function, and COUNT(*) needs to be applied after grouping.

3. Predict the output of the following query:

SELECT LCASE(MONTHNAME('2023-03-05')); The correct answer is:


iv. march
Explanation: MONTHNAME() returns the full name of the month in uppercase
(i.e., "March"), and LCASE() converts it to lowercase, resulting in "march".

4. With reference to SQL, identify the invalid data type.

The correct answer is:


iv. Month
Explanation: Month is not a valid data type. Valid data types are DATE,
INTEGER, and YEAR. Month can be used as part of a DATE data type or
function, but it is not itself a data type.

5. Write the output:

(a) SELECT ROUND(99.867, 2);


The output is:
99.87
Explanation: The number 99.867 is rounded to two decimal places.

(b) SELECT ROUND(63.97);


The output is:
64
Explanation: The number 63.97 is rounded to the nearest whole number.

6. Predict the output of the following queries:

i. SELECT POWER(5,3);
The output is:
125
Explanation: POWER(5,3) returns 5^3, which is 125.

ii. SELECT MOD(5,3);


The output is:
2
Explanation: MOD(5,3) returns the remainder when 5 is divided by 3, which is
2.

7. Help Reshma in predicting the output of the following queries:

i. SELECT ROUND(8.72,3);
The output is:
8.72
Explanation: The number 8.72 is already rounded to two decimal places, so
rounding it to 3 decimal places will not change it.

ii. SELECT ROUND(9.8);


The output is:
10
Explanation: The number 9.8 is rounded to the nearest whole number, which
is 10.

8. Predict the output of the following queries:

i. SELECT INSTR('[email protected]', '.');


The output is:
9
Explanation: The INSTR() function returns the position of the first occurrence
of a substring (in this case, the dot .), which is at position 9 in the string
[email protected].

ii. SELECT SUBSTR('[email protected]', 7, 4);


The output is:
'cbse'
Explanation: The SUBSTR() function extracts a substring starting at position 7
and taking the next 4 characters, resulting in 'cbse'.
iii. SELECT LEFT('[email protected]', 5);
The output is:
'exams'
Explanation: The LEFT() function extracts the leftmost 5 characters, resulting
in 'exams'.

9. Consider the given SQL string: "12#All the Best!"

Write suitable SQL queries for the following:

i. Returns the position of the first occurrence of the substring "the" in the
given string.
SQL Query:

sql

Copy code

SELECT INSTR('12#All the Best!', 'the');

The output is:


7
Explanation: The substring "the" first appears at position 7 in the string
"12#All the Best!".

ii. To extract the last five characters from the string.


SQL Query:

sql

Copy code

SELECT SUBSTR('12#All the Best!', -5);

The output is:


"Best!"
Explanation: SUBSTR() with a negative number extracts the last 5 characters
from the string, which results in "Best!".

You might also like