Hi All
I have a table as illistarted beloe that cotains three
mod types (x, y and z). How to I write a query that
will return the count of each mod type like a cross tab
ie.
x y z
4 2 3
CREATE TABLE ##Mods
(
ModType CHAR(1),
ModName VARCHAR(20)
)
INSERT INTO ##Mods VALUES ('X', 'CCC')
INSERT INTO ##Mods VALUES ('X', 'CCC')
INSERT INTO ##Mods VALUES ('X', 'CCC')
INSERT INTO ##Mods VALUES ('X', 'AAA')
INSERT INTO ##Mods VALUES ('Y', 'AAA')
INSERT INTO ##Mods VALUES ('Y', 'AAA')
INSERT INTO ##Mods VALUES ('Z', 'BBB')
INSERT INTO ##Mods VALUES ('Z', 'BBB')
INSERT INTO ##Mods VALUES ('Z', 'BBB')
Thanks in Advance.Hi
SELECT COUNT(CASE WHEN ModType='X' THEN 1 END)'X',
COUNT(CASE WHEN ModType='Y' THEN 1 END)'Y',
COUNT(CASE WHEN ModType='Z' THEN 1 END)'Z'
FROM ##Mods
<anonymous@.discussions.microsoft.com> wrote in message
news:14d5601c4156c$4b978910$a301280a@.phx
.gbl...
> Hi All
> I have a table as illistarted beloe that cotains three
> mod types (x, y and z). How to I write a query that
> will return the count of each mod type like a cross tab
> ie.
> x y z
> 4 2 3
>
> CREATE TABLE ##Mods
> (
> ModType CHAR(1),
> ModName VARCHAR(20)
> )
> INSERT INTO ##Mods VALUES ('X', 'CCC')
> INSERT INTO ##Mods VALUES ('X', 'CCC')
> INSERT INTO ##Mods VALUES ('X', 'CCC')
> INSERT INTO ##Mods VALUES ('X', 'AAA')
> INSERT INTO ##Mods VALUES ('Y', 'AAA')
> INSERT INTO ##Mods VALUES ('Y', 'AAA')
> INSERT INTO ##Mods VALUES ('Z', 'BBB')
> INSERT INTO ##Mods VALUES ('Z', 'BBB')
> INSERT INTO ##Mods VALUES ('Z', 'BBB')
> Thanks in Advance.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment