Databases SQL Reporting by Example Day 2: Advanced Selecting Day 2: Review

sujal Khatiwada
PRO
sujal Khatiwada
Pro Student 291 Points

SQL Practice Problem

There are 267 employees and 15 with last names starting with 'A'. What does this return?

SELECT COUNT(1) FROM EMPLOYEES GROUP BY 'A';

1 Answer

Dale Severude
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Dale Severude
Full Stack JavaScript Techdegree Graduate 71,300 Points

The GROUP BY isn't doing anything because there is not a valid table value to group by. So the number of employees gets counted, which is 267.

To count the last names beginning with 'A' the code would look something like this:

SELECT COUNT(1)
FROM EMPLOYEES
WHERE EMPLOYEES.LAST_NAME LIKE 'A%'