ValleyENT
asked on
SQL Column Count
Hey All,
Trying to write a simple query that will look in my table dbo.Profile count the total number of entries in 'City', then get a count for each city found.
Example:
Total = 140,000
Peoria = 150 entrie(s)
Ajo = 1 entrie(s)
Glendale = 9000 entrie(s)
Is this possible?
Trying to write a simple query that will look in my table dbo.Profile count the total number of entries in 'City', then get a count for each city found.
Example:
Total = 140,000
Peoria = 150 entrie(s)
Ajo = 1 entrie(s)
Glendale = 9000 entrie(s)
Is this possible?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This will do
SELECT city, count(*) AS cnt
FROM dbo.Profile
GROUP BY city
WITH rollup
ValleyENT,
Assuming City is a column in the table Profile, you can execute the following query to get the results you are looking for
select City, count(*) from Profile group by City
if you really want the "Total" as well you could so something like this
select 'Total', count(*) from Profile
union all
select City,Count(*) from Profile group by City
Assuming City is a column in the table Profile, you can execute the following query to get the results you are looking for
select City, count(*) from Profile group by City
if you really want the "Total" as well you could so something like this
select 'Total', count(*) from Profile
union all
select City,Count(*) from Profile group by City
ASKER
How would I include the corrosponding State if the column name was STATE?
SELECT City, COUNT(City) as "Total City(s)"
FROM dbo.PatientProfile
GROUP BY City ORDER By City
do you want it included w/ the city information or a new query just for state information?
ASKER
included please.
Select City, State, count(City) as "Total Cities" from dbo.PatientProfile group by City,State order by City, State
from profile
group by city