Hej
Kan man göra en select sats där man får tre olika count.
id typ
1 0
2 0
3 1
4 0
5 2
6 2
Jag vill gå ut tre count:
typ0 = 3
typ1 = 1
typ2 = 2
Går det med en select eller ska jag köra tre select satser?
3 svar · 304 visningar · startad av Addeladde
Hej
Kan man göra en select sats där man får tre olika count.
id typ
1 0
2 0
3 1
4 0
5 2
6 2
Jag vill gå ut tre count:
typ0 = 3
typ1 = 1
typ2 = 2
Går det med en select eller ska jag köra tre select satser?
Du kan göra på båda setten beroende på hur du vill att det ska visas.
select 'typ0' as typ,count(typ) as cnt from tabell where typ=0
union
select 'typ1' as typ,count(typ) as cnt from tabell where typ=1
union
select 'typ2' as typ,count(typ) as cnt from tabell where typ=2
eller
select (select count(typ) from tabell where typ=0) as typ0
,(select count(typ) from tabell where typ=1) as typ1
,(select count(typ) from tabell where typ=2) as typ2
select typ, count(*) from tabell
group by typ
Tack!