Computer scienceFundamentalsSQL and DatabasesBasics SQLRetrieving Data

GROUP BY statement

Namesakes

Report a typo

employees table contains data about personnel of QAZ Industries Corp.

department_id last_name first_name salary start_date
12 Johnson Martin 80000 2012-03-11
23 Dawson Sharon 90000 2019-09-17
20 Ricksen Dario 93000 2020-02-18
20 Ricksen Kirk 100000 2006-05-19
34 Lee Lukas 70000 1999-12-12
65 Lee Becky 60000 2013-08-01
12 Johnson Colin 75000 2013-11-02
20 Johnson Martha 40000 2017-01-18

How many rows would the result of the query have?

SELECT last_name, COUNT(DISTINCT department_id) as departments
FROM employees
GROUP by last_name
HAVING departments = 2;
Enter a number
___

Create a free account to access the full topic