SBB
SBB

Reputation: 8970

TSQL Query count with multiple columns

I have a table that is structured like so:

Account, Tag
------------
123, dog
123, owl
456, pig
456, goat
678, dog
789, owl

I need to create a statement that will return the following data:

Tag name with the total number of account it's on:

Dog 2
owl 2
pig 1
goat 1

Upvotes: 0

Views: 38

Answers (1)

Raphaël Althaus
Raphaël Althaus

Reputation: 60493

select Tag, count(*)
from table
group by Tag

Upvotes: 3

Related Questions