Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return count and not count in a SQL query?

Tags:

sql

select

oracle

If I have a table

AgentID | IsNew | TeamID
1         N       1
2         Y       2
3         Y       2
4         N       2
5         Y       1

I want to return the following from a query:

Team | CountIsNew = N | CountIsNew = Y
1      1                1
2      1                2

Is there a way I can do this?
Using Oracle 10

like image 863
Gribbler Avatar asked Dec 13 '22 22:12

Gribbler


1 Answers

SELECT  team, SUM(DECODE(IsNew, 'N', 1, 0)), SUM(DECODE(IsNew, 'Y', 1, 0))
FROM    mytable
GROUP BY
        team
like image 190
Quassnoi Avatar answered Jan 08 '23 21:01

Quassnoi