---
title: "Tre olika count i en select sats"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/160409-tre-olika-count-i-en-select-sats"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "Addeladde"
published: "2007-05-16T19:38:15.000Z"
updated: "2007-05-16T20:19:19.000Z"
replies: 3
views: 327
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/databaser-sql/160409-tre-olika-count-i-en-select-sats"
---

# Tre olika count i en select sats

## #1 — Addeladde, 2007-05-16T19:38Z

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?

Permalänk: https://www.webforum.nu/p/160409

## #2 — yohpops, 2007-05-16T20:11Z

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
```

Permalänk: https://www.webforum.nu/p/1978374

## #3 — @nders, 2007-05-16T20:16Z

```
select typ, count(*) from tabell
group by typ
```

Permalänk: https://www.webforum.nu/p/1978379

## #4 — Addeladde, 2007-05-16T20:19Z

Tack!

Permalänk: https://www.webforum.nu/p/1978380

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/160409-tre-olika-count-i-en-select-sats
