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

Extra SUM in query

I made a query with some totals. One of these totals I only get when
using a subquery. I believe it must be possible to get the resulkt in
one query

ArtNr Total #order #customer
123789 460 20 8

So i'm selling an article in 20 different orders to 8 different
customers witrh a total of 460 pieces.
When I make a query with sum[artNr] number[orders] and number[customers]
the result in the customers collumn wil always be one. Only using the
subquery gives the right result.
Is it possible to make this query without the sub query

Peters

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #1
1 4322
Actually, no. Access cannot sum at different grouping levels in the same
query. A subquery is one way to handle the problem. Another is to do a
query that rolls up the smallest level and groups by the next level up,
then make a query of that query that sums the 2 lowest levels, and groups
by the rest... until all levels of aggregation are rolled up.

For example, let's say you have tblOrderLine, tblOrder, and tblCustomer.

First query - qryOrderSum
SELECT tblOrder.CustomerID, tblOrder.OrderID,
Sum(tblOrderLine.PiecesQty) As PiecesQtySum
FROM tblOrder
LEFT JOIN tblOrderLine On tblOrder.OrderID = tblOrderLine.OrderID
GROUP BY tblOrder.OrderID

Next query - qryCustomerOrderSum
SELECT qryOrderSum.CustomerID,
Sum(qryOrderSum.PiecesQtySum) As PiecesQtySum, Count(*) As OrderCount
FROM tblCustomer
LEFT JOIN qryOrderSum ON tblCustomer.CustomerID = qryOrderSum.CustomerID
GROUP BY tblCustomer.CustomerID

Finally - qryOverallOrderSum
SELECT Count(*) As CustomerCount,
SUM(qryCustomerOrderSum.PiecesQtySum) As PiecesQtySum,
SUM(qryCustomerOrderSum.OrderCount) As OrderCountSum
FROM qryCustomerOrderSum

On 19 Oct 2003 06:31:22 GMT, Access <as***@devdex.com> wrote:
I made a query with some totals. One of these totals I only get when
using a subquery. I believe it must be possible to get the resulkt in
one query

ArtNr Total #order #customer
123789 460 20 8

So i'm selling an article in 20 different orders to 8 different
customers witrh a total of 460 pieces.
When I make a query with sum[artNr] number[orders] and number[customers]
the result in the customers collumn wil always be one. Only using the
subquery gives the right result.
Is it possible to make this query without the sub query

Peters

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #2

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

Similar topics

2
by: Nick | last post by:
In VS 2003 and VS 2005 beta 2 I am trying to write a simple program. It has a datagrid and a textbox along with a menubar. There is a command in the menu bar which is "Run Query" and has the...
1
by: Peter | last post by:
Ik wil een query met een extra totaaltelling over aantal klanten die een bepaald produkt afnemen. Het is me nu gelukt met een extra subquery maar dit lijkt me omslachtig. In de tabel staat steeds...
5
by: Marco Gallo | last post by:
I've been trying to get rid of extra spaces in a table that I created with addresses in it. For instance in a field called TEST, I got the following address: " 1 main st Apt A "...
6
by: Jeremy | last post by:
I have a datasheet subform that is based off an ADO recordset. All is fine excpet the query results are displayed oddly. Rather than displaying the results as say 95.43, it displays it as...
8
by: Mike Nolan | last post by:
As far as I can tell, Postgres has no equivalent to greatest and least functions in Oracle. Yes, you can do the same thing with a case statement, but at the expense of writing MUCH longer SQL...
11
by: cdkorzen | last post by:
I'm sorry if this is a rehash, but all I see is the same info. Here's my debacle: I CAN get the PATH_INFO to work. With ANYTHING but ASP. Python, Perl, Cmd files... works fine. ASP can't...
3
by: dchristjohn | last post by:
I am currently developing a small windows application using Visual Basic via Visual Studio 2005. My database resides on a SQL 2000 server. I have a table with three fields: id (int, Not Null)...
9
by: davek | last post by:
(posted to: php.general, comp.lang.php, alt.php, alt.php.sql) I have a form where registered users on my site can edit their login details. For some reason, the script is inserting an extraneous...
2
by: mnms | last post by:
Hi, I'm wondering if it's possible "manually" add an extra value to a combobox list. At the moment I have two fields, one "transparent" is a checkbox that lets you define a colour as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.