SQL Group Filtering: SQL provides different clauses for filtering data at different stages of query execution.
Key Differences:
Example Demonstration:
SELECT department, AVG(salary) FROM employees GROUP BY department HAVING AVG(salary) > 50000; ← Filters after grouping
Why HAVING is correct:
The correct answer is (2) having, as it's the only clause that applies conditions after groups are formed.
On a relation named Loan of a bank:
Based on the following schema,
sailors (sailor-id, sailpr-name, age):
boats (boat-id, boat-name, colour):
reserves (sailor id, boat id, day);
What does the following SQL query imply?
SELECT S.sailor_name FROM sailors S, boats B, reserves R
WHERE S.sailor_id = R.sailor_id AND R.boat_id = B.boat_id
AND (B.colour = 'red' OR B.colour = 'green');
Based on the following schema,
sailors (sailor-id, sailpr-name, age):
boats (boat-id, boat-name, colour):
reserves (sailor id, boat id, day);
What does the following SQL query imply?
SELECT S.sailor_name FROM sailors S WHERE S.sailor_id IN
(SELECT R.sailor_id FROM reserves R WHERE R.boat_id >= 103);
Re-arrange the following parts of a sentence in their correct sequence to form a meaningful sentence.
(A) the decision was announced publicly
(B) after weeks of speculation and media reports
(C) by the government officials
(D) during a press conference
Choose the correct answer from the options given below: