How can I get the number of employees whose name starts with A or B? The result should look like below.
=========== A | B | =========== 5 | 8 | -----------
You can always use CASE
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 adding 1 to column A for every first_name starting with A.
Based on my understanding. Below the query, two columns are returned : 1: Initial Alphabet, 2: Count.
SELECT LEFT(employees, 1) , Count(LEFT(employees, 1)) FROM TableName GROUP BY LEFT(employees, 1)