vinWin
vinWin

Reputation: 603

Counting rows distinctly on multiple values from in clause in oracle sql

I am looking at counting rows distinctly on multiple values from in clause in oracle sql, so that it retrieves output in just 1 query

I tried running below query which leads me one column output on # of A22 ID matching rows count.

select count(*) as A22 from TABLE_NAME where ID = 'A22' ;

If I run below query on multiple ID's using various ID values with in clause it gets me total ( summation) count, but don't see direct option in query to retrieve 4 column value of count per ID time

select count(*) from TABLE_NAME where ID in ('A22','B22', 'C22', 'D22')

Apart from running same count* query 4 times or in loop, is there a better way to get 4 ID count values from the table?

Upvotes: 0

Views: 21

Answers (1)

Littlefoot
Littlefoot

Reputation: 142788

Looks like

select id, count(*) 
from TABLE_NAME 
where ID in ('A22','B22', 'C22', 'D22')
group by id

Upvotes: 1

Related Questions