How can I get a count of employees whose name starts with A or B? The result should look like the table bellow.
===========
A | B |
===========
5 | 8 |
-----------
How can I get a count of employees whose name starts with A or B? The result should look like the table bellow.
===========
A | B |
===========
5 | 8 |
-----------
You can always use CASE
SELECT
SUM(case when first_name like 'A%' then 1 else 0 end) 'A' ,
SUM(case when first_name like 'B%' then 1 else 0 end) 'B'
FROM tableName
Query basically means add 1 to column A for every first_name that starts with A.
Based on my understanding. Below Query will return two columns 1 :Starting Alphabet, 2: Count.
SELECT LEFT(employees, 1) , Count(LEFT(employees, 1)) FROM
TableName GROUP BY LEFT(employees, 1)