|
Posted by getinked on 11/21/05 23:39
declare @v table (ids int, age int)
INSERT INTO @v (ids, age)
VALUES (23586, 3)
INSERT INTO @v (ids, age)
VALUES (23586, 3)
INSERT INTO @v (ids, age)
VALUES (23586, 2)
INSERT INTO @v (ids, age)
VALUES (23586, 2)
INSERT INTO @v (ids, age)
VALUES (23586, 1)
INSERT INTO @v (ids, age)
VALUES (23586, 1)
INSERT INTO @v (ids, age)
VALUES (23586, 1)
INSERT INTO @v (ids, age)
VALUES (23586, 1)
INSERT INTO @v (ids, age)
VALUES (23586, 1)
SELECT v.ids
, COUNT(CASE WHEN age = 1 THEN 1 END) AS Age1
, COUNT(CASE WHEN age = 2 THEN 1 END) AS Age2
, COUNT(CASE WHEN age = 3 THEN 1 END) AS Age3
, COUNT(CASE WHEN age = 4 THEN 1 END) AS Age4
FROM @v v
GROUP BY ids
Navigation:
[Reply to this message]
|