Reply to Re: Need help with Count function and temporary tables

Your name:

Reply:


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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация