161. Week-14 Quiz Explaination
161. Week-14 Quiz Explaination
Q1. What will be the result after executing the below query:
Option 1- 11
Option 2- 3
Option 3- 103
Option 4- 104
Artists TABLE:
As ID column is Primary key and on auto-increment mode, auto-increment will try to give the
next available value and this is done by reordering the rows in sorted order, and then
whichever row comes last autoincrement is done on that row value.
In this case, ID = 102 would come last, so the next value for ID would be 103
Now, let's discuss the result of `SELECT max(ID) from artists;`. The query is asking for the
maximum "ID" value in the "artists" table.
Hence, in our case, the correct answer is "Option 3: 103" because 103 is the maximum "ID"
value in the table.
Q2. No of records in the albums table after the below query is executed (given that query of
Q1 is already executed):
Option 1- 1
Option 2- 3
Option 3- 4
Option 4- 2
Correct- 1
Explanation: Second insert query will raise an error as ArtistID = 1 is not present in the
artists table. So after that, no query will be executed. Only one insert query to the albums
table is executed.
Q3. Consider the following table structure and content for the 'Student' table:
Which of the following UPDATE statements will execute successfully for the Student
table?
Which of the following UPDATE statements will Update 2 rows for the Student table?
Explanation :
Option 2 : Will only update one row.
Option 3 : Id column can’t have value NULL, because of NOT NULL constraint.
Option 4 : Will only update one row. Last row
Explanation :
Option 3: A primary key column that also serves as a foreign key reference in another
table
Primary key columns serve as unique identifiers for records in a table, and they are
typically not updated because changing the primary key would affect the integrity of
the data and potentially break relationships with other tables where this key is used
as a foreign key. Therefore, primary key columns are not typically updated.
Options 1 and 2 are not necessarily true in all cases. You can update columns of
DATE type, and you can also update columns that allow NULL values if the table
permits it.
Q6: Customer table consists of a column Balance. The table contains a single row
with a value of 20000.56. What will be the values of ROUND, ROUND1, and FLOOR
when the below query is executed?
Option 1: 7
Option 2: 5
Option 3: 8
Option 4: 3
This SQL query will calculate the length of the substring of the string "DESOUZA." It
takes a substring of "DESOUZA" starting from the 3rd character (index 3) and takes
the next 7 characters. “SOUZA” - Length 5
Which of the following query displays the data in the following format:
Explanation: In Option 3 query, 'dd' is used to extract the day of the month as a
two-digit number (e.g., '08' for January 8th), and 'mm' is used to extract the month as
a two-digit number (e.g., '01' for January).
Q9: Which of the following aggregate functions can be applied on both number and
character-typed columns? [Choose any THREE]
Option 1: MIN
Option 2: MAX
Option 3: AVG
Option 4: COUNT
Option 5: SUM
Q10: Table T exists with single column A having 4 rows with values – 100, 200, NULL,
300. What is the output of the following query?
Option 1: 300
Option 2: NULL
Option 3: No rows
Option 4: Error is thrown
Explanation: No rows have a value greater than 1000, so NULL will be the output.
Q11: Which of the following date function can be used to get the timestamp from a
database?
Option 1: SYSDATE
Option 2: SYSTEMDATE
Option 3: SYSTIMESTAMP
Option 4: SYSTEMTIMESTAMP
Explanation: SYSTIMESTAMP
Q12: Which of the following statement(s) is/are FALSE about order by clause?
[Choose any TWO]
Q13: Consider the following “Quotation” table. How many rows would be displayed
when the following query is executed?
Option 1: 2
Option 2: 4
Option 3: Error is thrown
Option 4: 5
Explanation :
4 Groups will be formed : (S1001, I1012), (S1002, I1012), (S1003, I1013) and (S1004,
I1013)
Q14: Given the employee table as input, choose the query that displays
department-wise average salaries sorted in descending order.
Option 1: SELECT AVG(Salary) AvgSal, Dept FROM Employee GROUP BY Dept ORDER
BY 1
Option 2: SELECT AVG(Salary) AvgSal, Dept FROM Employee ORDER BY AVG(Salary)
GROUP BY Dept
Option 3: SELECT AVG(Salary) AvgSal, Dept FROM Employee GROUP BY Dept
ORDER BY AvgSal DESC
Option 4: SELECT Dept, AVG(Salary) AvgSal FROM Employee GROUP BY 1 ORDER BY
2 DESC
1. Option 1: This query calculates the average salary (`AVG(Salary)`) for each
department (`Dept`) and then attempts to order the results by the first column
(`ORDER BY 1`). However, it does not specify a descending order (`DESC`), so the
default sorting order will be ascending.
2. Option 2: In this query, it attempts to order the result set by the calculated average
salary (`AVG(Salary)`) before the grouping (`GROUP BY Dept`). This is not valid
because the aggregation function is used in the `ORDER BY` clause before the
grouping operation. This query would not produce error.
3. Option 3: This is the correct query. It first calculates the average salary for each
department and then orders the results in descending order by the alias `AvgSal`
using `ORDER BY AvgSal DESC`.
Q15: Which of the following statement(s) is/are FALSE about UNION? [Choose any
TWO]
Option 1: Column Names in all queries in a UNION must match position wise
Option 2: UNION can be used with an UPDATE statement
Option 3: Data Types in all queries in a UNION must match position wise
Option 4: The number of columns must match the query