How to get an invoice for employees whose name begins with the alphabet A and B

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  |
-----------

      

+3


source to share


2 answers


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 adding 1 to column A for every first_name starting with A.

+6


source


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) 

      

+4


source







All Articles