Solved

SQL query - getting a list of counts from a single table

Posted on 2003-12-12
2
391 Views
Last Modified: 2010-05-18
Hey,

If i have a table 'cars' in my DB something like:

      id      type      color
      1      2      blue
      2      2      blue
      3      3      red
      4      6      red
      5      5      blue
      6      5      blue
      7      2      green

If i want to return the total number of entries per type,
 and also return the type in the same row.
Is this possible and how would i do it?

Select distinct type from cars.....will return a list of the distinct types

select count(*) from cars as Total.....will return the complete total of all cars

But can i get a result in the following format

      count      type
      3      2
      1      3
      2      5
      1      6
where count contains the total number of cars per type?


0
Comment
Question by:mcgettiu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 125 total points
ID: 9927718
Hi mcgettiu,

Select Type,Count(*) From Cars Group By Type

Is all you need.

Tim Cottee MCSD, MCDBA, CPIM
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 

Author Comment

by:mcgettiu
ID: 9927735
Thanks a mill
You got me out of a jam
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

734 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