473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Counting items and returning values

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?
Nov 18 '05 #1
3 1280
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
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:ks*******************@news-text.cableinet.net...
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?
Nov 18 '05 #2
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

--
Manohar Kamath
Editor, .netWire
www.dotnetwire.com
"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:ks*******************@news-text.cableinet.net...
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?

Nov 18 '05 #3
if the name of the column is "name":
SELECT name, COUNT(name)
GROUP BY name

HTH,
-Cliff

"Andrew Banks" <ba****@nojunkblueyonder.co.uk> wrote in message
news:ks*******************@news-text.cableinet.net...
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?

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bryanilton | last post by:
Hi, I'm new to PHP and I have a question that I think has a simple answer but I just can't figure it out so I'm really hoping that one of you gurus can help me out. I'm trying to return data...
6
by: Elbert Lev | last post by:
Please correct me if I'm wrong. Python (as I understand) uses reference counting to determine when to delete the object. As soon as the object goes out of the scope it is deleted. Python does...
16
by: walexand | last post by:
I use the database mysql v.4. My problem is... I have a select like: select * from user where language = "de"; the result are then: id name =================== 1 max
11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
18
by: ChadDiesel | last post by:
I appreciate the help on this group. I know I've posted a lot here the last couple of weeks, but I was thrown into a database project at my work with very little Access experience. No other...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
4
by: Ron | last post by:
I've got a listbox that holds a list of groups. Users can select a group, hit the remove button and the group should be removed from the listbox. The only problem is that no matter which group you...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
14
by: Dan | last post by:
Is this discouraged?: for line in open(filename): <do something with line> That is, should I do this instead?: fileptr = open(filename) for line in fileptr: <do something with line>
0
by: randy.buchholz | last post by:
When binding a control to a datasource (SQL) using the configure data source or editing the SQL Query both VS2005 and 2008 have always shown duplicate (double) values in the controls list on all of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.