Counting items and returning values

A

Andrew Banks

I have a table of product orders. It contains a row for "platform" and I
need to return how many times each platform is listed in the DB

Example data for platform could be:
XBOX
XBOX
XBOX
PLAYSTATION
PLAYSTATION
GAMECUBE
PLAYSTATION

I'd like the data to be returned as

XBOX - 3
PLAYSTATION - 3
GAMECUBE - 1

How would I go about doing this please?
 
T

Tom Moreau

Depends on what you mean by "in the database". If the data are kept in one
table, then the following would do it:

select
Platform
, count (*)
from
MyTable
group by
Platform


--
Tom

---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql


I have a table of product orders. It contains a row for "platform" and I
need to return how many times each platform is listed in the DB

Example data for platform could be:
XBOX
XBOX
XBOX
PLAYSTATION
PLAYSTATION
GAMECUBE
PLAYSTATION

I'd like the data to be returned as

XBOX - 3
PLAYSTATION - 3
GAMECUBE - 1

How would I go about doing this please?
 
M

Manohar Kamath [MVP]

This is more of an SQL question, so please post in relevant groups only.

Anyways, the answer to your question in q SQL query that return the count of
each platform:

SELECT Platform, Count(*) AS PlatformCount FROM myTable GROUP BY Platform
 
C

Cliff Harris

if the name of the column is "name":
SELECT name, COUNT(name)
GROUP BY name

HTH,
-Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top