Pergunta

I have table like this in my database oracle.

WITEL-KATEGORI-MONTH

A------------R------------2

A------------S------------3

B------------S------------2

C------------T------------3

B------------T------------2

A------------T------------3

C------------S------------2

C------------S------------2

A------------S------------2

A------------S------------2

A------------S------------3

A------------S------------3

B------------S------------3

anyone have idea, what query that can show data like this :

WITEL--COUNT-1--COUNT-2

A-----------3-----------5

B-----------1-----------2

C-----------2-----------2

First colum is witel, second colum is count of witel WHERE KATEGORI=S AND MONTH=3 but third column is count of all witel where KATEGORI=S. thank you

Foi útil?

Solução

You want conditional aggregation, which is using an aggregation function like SUM() with a CASE statement as an argument:

select witel,
       sum(case when KATEGORI = 'S' AND MONTH = 3 then 1 else 0 end) as count1,
       sum(case when KATEGORI = 'S' then 1 else 0 end) as count2
from table t
group by witel;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top