473,386 Members | 1,741 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,386 software developers and data experts.

Disctinct query plus total column value

Hi, hopefully someone can help me with this query. Basically I have 3 columns in 1 table, they are:

NAME
SIZE
NUMBER

I need a query that will return the NAME and SIZE as distinct values and then add the NUMBER together to give a total. An example of the results before the query would be:

NAME SIZE NUMBER
Joe A 1
Stan A 6
Joe B 3
Joe C 12
Stan B 1
Joe A 3
Stan C 2
Joe B 2
Stan A 2

Using the following query will return the distinct values:

SELECT DISTINCT Name, Size
FROM Table1
ORDER BY Name, Size

Results will be:

Joe A
Joe B
Joe C
Stan A
Stan B
Stan C

What I am trying to do now is take the NUMBER for each entry and total that number so the results will be:

Joe A 4
Joe B 5
Joe C 12
Stan A 8
Stan B 1
Stan C 2

Your help will be much appreciated.

Sean
Jan 30 '12 #1

✓ answered by Rabbit

What you're looking for is an aggregate query, there's no need for a distinct.
Expand|Select|Wrap|Line Numbers
  1. SELECT groupingField, SUM(valueField)
  2. FROM someTable
  3. GROUP BY groupingField

3 1842
Rabbit
12,516 Expert Mod 8TB
What you're looking for is an aggregate query, there's no need for a distinct.
Expand|Select|Wrap|Line Numbers
  1. SELECT groupingField, SUM(valueField)
  2. FROM someTable
  3. GROUP BY groupingField
Jan 30 '12 #2
Thank you for your quick reply. I will test this and let you know how I get on but it seems so obvious now :o)
Jan 30 '12 #3
That was the answer, thanks
Jan 30 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Matthias Haffke | last post by:
Ok, this is a tricky question for the pro's: My access sheet: line, id a, id b, val% ---------------- 1, a, ac, 0.04 2, a, ac, 0.28 3, a, ac, 0.015 4, a, ac, 0.205
2
by: worli | last post by:
Hi All, I have a strange requirement. I have a dynamic input numeric data stream e.g. 2, 2, 4, 5 etc.... ( each input number range from 1 to 10 ). lets take a simple case where all inputs will...
0
by: Terry Olsen | last post by:
Is there a way to get the total column count in a DataGrid? I can get the total _visible_ columns, but I need to know how many _total_ columns are in my grid. Thanks!
0
by: Joe Meng | last post by:
Greetings, I've seen this question asked and answered here, just not completely yet. I'm wondering how to use a column value as a table name in another query. So far it's looking like you must...
1
by: Byomokesh | last post by:
Hi I am trying to cell count and match in tgroup cols value in XML file. if cell count and tgrou cols value is mismatch, its showing error. My xml -------------- <tgroup cols="3"> <colspec...
3
by: Manikandan | last post by:
Hi, I have table with three columns as below table name:exp No(int) name(char) refno(int) I have data as below No name refno 1 a 2 b 3 c
1
by: Dolly Kumari | last post by:
Hi, I want to write a Program in vb which will accept any Access database (.mdb file) and search a particular column value in all tables present in the database and will give the result as table...
2
by: jdrake | last post by:
Hi, I have a large table with a 'datetime' column that has date and time values in it. The data is in this format: 2007-10-02 09:54:00.000 The table is called 'profile' and the column...
1
by: silversubey | last post by:
I am using a query to total hours (Cltbudget.CBudhours) and dollars (CltBudget.CBudFee) Grouped by client names (Cltbudget.CBudCltName). here is the Query: SELECT CltBudget.CBudCltName AS Client...
1
by: erics44 | last post by:
Hi I have a Matrix in a report and i want the total column to sum a different field that is in the column group, is there any way of doing this? here is an example of my matrix ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.