Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi friends I have a table with two column example: Table Name:Code_Project
Column Name: Id,Name

ID Name
20101234 A
20101235 B
20101236 C
20111234 D
20111235 E
20111236 F
20121234 G
20121235 H
20131234 J

I need Output as Follows
ID Count_id
2010 3
2011 3
2012 2
2013 1

I Have one query
SQL
select   substring(Id,1,4) as Id,count(Id) as count_id from Code_Project group by Id

here i am separate count....
Posted
Updated 8-Mar-12 22:57pm
v3

1 solution

You almost got it; but little tweak at group by level.

SQL
select substring(Id,1,4) as Id,count(Id) as count_id from Code_Project group by substring(Id,1,4) 
 
Share this answer
 
Comments
itsureshuk 9-Mar-12 4:56am    
thanks
member60 9-Mar-12 4:56am    
my 5!
bluesathish 9-Mar-12 4:59am    
i think me and ganesansenthilvel posted the same at a same time, thats why i delete my posted solution.
itsureshuk 9-Mar-12 5:10am    
k
ProEnggSoft 9-Mar-12 12:06pm    
Good answer. My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900