SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE departments ( department_id serial, department_name varchar(64) ); INSERT INTO departments VALUES (1, 'Dep1'), (2, 'Dep2'); CREATE TABLE employees ( id serial, department_id int, employee_name varchar(64) ); INSERT INTO employees VALUES (1, 1, 'Emp1'), (2, 1, 'Emp3'), (3, 2, 'Emp3'); SELECT COALESCE(departments.department_name, 'Total') AS department_name, COUNT(*) as Count_employees FROM employees JOIN departments ON employees.department_id = departments.department_id GROUP BY ROLLUP(departments.department_name) ORDER BY departments.department_name;
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear