Solved

Sql select count and distinct...

Posted on 2011-03-06
4
433 Views
Last Modified: 2012-05-11
I have this query which returns car manufacturers...
SELECT DISTINCT [Make] FROM [VehicleSpecs] ORDER BY [Make]

How can I modifiy this query to also return the count for each make?

0
Comment
Question by:evo_x
  • 2
  • 2
4 Comments
 
LVL 15

Expert Comment

by:derekkromm
Comment Utility
SELECT [Make],count(*) FROM [VehicleSpecs] group by [Make] ORDER BY [Make]
0
 
LVL 2

Author Comment

by:evo_x
Comment Utility
But how can I assign a field name to count ? because this way I can't assign the count field to the asp.net control.
0
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
Comment Utility
SELECT [Make],count(*) as [MakeCount] FROM [VehicleSpecs] group by [Make] ORDER BY [Make]
0
 
LVL 2

Author Comment

by:evo_x
Comment Utility
Thanks !
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now