Jack Sander Jack Sander - 2 months ago 6
SQL Question

Listing specific values in SQL

I have a table here named TEST. I want to display the number of left-handed and right-handed persons of my family.

How would one do so? Here is what I did:

NAME, HANDED
Jeffrey, R
Ashley, L
Bob, R
Dad, R
Mom, R

SELECT HANDED, COUNT(HANDED)
AS COUNT_HANDED
FROM TEST
WHERE HANDED = 'L' OR HANDED = 'R';


I want the output to be like this:

HANDED, COUNT_HANDED
L, 1
R, 4


Not sure how I could do something like this. Any clue?

Answer

Simple!

SELECT HANDED, COUNT(HANDED)
AS COUNT_HANDED
FROM TEST
GROUP BY HANDED;