Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have to make query

My table structure is like this

towncodeNo               TownName
2023001                   M1
2023001                   M1
2031025                   Z1
2031025                   Z1
2031030                   Z1


Result should be

Townname      Total
M1             1
Z1             2


Kindly help me to make query using SQLServer 05
Posted
Updated 27-Mar-12 0:10am
v2

Try:
SQL
SELECT TownName, COUNT(TownName) - 1 AS Total FROM myTable GROUP BY TownName
 
Share this answer
 
SQL
select TownName, Count(Distinct(towncodeNo )) from tblSample group by TownName;
 
Share this answer
 
v3
Comments
Amir Mahfoozi 27-Mar-12 6:11am    
+5
qasimidl 27-Mar-12 7:21am    
great its working
thanks

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