MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

SQL

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
SELECT THE TRUE STATEMENT
A
Aggregate functions can be used in WHERE clause.SELECT Id, EName, Salary, Dept FROM Employee E1 WHERE Salary = MAX(Salary);
B
Aggregate functions can be used in WHERE clause even if GROUP BY is used.SELECT DEPT, SUM(Salary) FROM Employee WHERE SUM(Salary) > 90000 GROUP BY DEPT
C
Nested aggregate function can be used in SELECT clause without GROUP BY clause.SELECT MAX(AVG(Salary)) FROM Employee;
D
Order By cannot be used on columns on which Grouping is not being done.SELECT Dept, SUM(Salary) FROM Employee GROUP BY Dept ORDER BY Designation;
Explanation: 

Detailed explanation-1: -Answer: D. Group functions cannot be used in WHERE clause. The can appear in SELECT, HAVING and ORDER BY clause.

Detailed explanation-2: -Group functions on columns cannot be accurately used on columns that contain NULL values.

Detailed explanation-3: -In MySQL, when you try to select a column that isn’t used in the GROUP BY clause, or in an aggregate function inside the statement, it is not a valid statement according to SQL standard and will cause an error.

Detailed explanation-4: -The Group By statement is used to group together any rows of a column with the same value stored in them, based on a function specified in the statement. Generally, these functions are one of the aggregate functions such as MAX() and SUM(). This statement is used with the SELECT command in SQL.

There is 1 question to complete.