Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 count and group by

Author  Topic 

misterish
Starting Member

10 Posts

Posted - 2011-02-17 : 11:24:00
Hi,
I have a query where I am returning the counts of records grouped by a varchar field. That field has values formatted like:

01.01
01.02
01.03
02.01
etc....

Right now I get results like:

count label
124 01.01
345 01.02
35 01.03

What I would like to do is merge all counts that start with the 2 digits before the dot. So:

count label
819 01
1254 02

Is this possible?

Original query:

SELECT COUNT(*) AS count, dbo.screen_view.screen_id_friendly
FROM dbo.screen_view
GROUP BY dbo.screen_view.screen_id_friendly

Thank you!

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-02-17 : 11:52:55
SELECT Count(*) as [Count],left(dbo.screen_view.screen_id_friendly,2)
FROM dbo.screen_view
GROUP BY left(dbo.screen_view.screen_id_friendly,2)

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

misterish
Starting Member

10 Posts

Posted - 2011-02-17 : 12:06:48
YES! Thank you!
Go to Top of Page
   

- Advertisement -