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

sub totals in query

In a query, a category has a number of products identified by numbers,
i.e. 240, 300, 560 etc. Each of these products can have any number of
items each with its own value. I need the sum of various groups of
products. Say products from 240 to 330, sum of the values. Sum of
values from 340 through 456, AND 990 through 1240. If there is a simple
solution that I'm just missing, please point me in the right direction.
Is it possible to do this in a simple query?

Thanks,

Andy Fox

Nov 13 '05 #1
5 1522
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use something like this:

SELECT
Switch(Product Between 240 And 330, "A",
Product Between 340 And 456, "B",
Product Between 990 And 1240, "C") As ProductGroup,
Sum(value_column) As ValueTotal
FROM ...
WHERE ...
GROUP BY Switch(Product Between 240 And 330, "A",
Product Between 340 And 456, "B",
Product Between 990 And 1240, "C")

If the Between doesn't work use:

Switch(240 <= Product And Product <= 330, "A",
340 <= Product And Product <= 456, "B",
990 <= Product And Product <= 1240, "C")

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlSKMIechKqOuFEgEQI2gQCeIG/537dKVRhQ4+DWtxzWHpvD7CEAoOF0
iK43JQQ3lfl6S9DiSPGkArTl
=lvSc
-----END PGP SIGNATURE-----
green fox wrote:
In a query, a category has a number of products identified by numbers,
i.e. 240, 300, 560 etc. Each of these products can have any number of
items each with its own value. I need the sum of various groups of
products. Say products from 240 to 330, sum of the values. Sum of
values from 340 through 456, AND 990 through 1240. If there is a simple
solution that I'm just missing, please point me in the right direction.
Is it possible to do this in a simple query?

Nov 13 '05 #2
MGFoster,
Switch? Like TransactSQL CASE? Neat. Didn't know that was supported in
Jet SQL.
--
Alan Webb
kn*******@SPAMhotmail.com
"It's not IT, it's IS
"MGFoster" <me@privacy.com> wrote in message
news:SS*****************@newsread2.news.pas.earthl ink.net...
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Use something like this:

SELECT
Switch(Product Between 240 And 330, "A",
Product Between 340 And 456, "B",
Product Between 990 And 1240, "C") As ProductGroup,
Sum(value_column) As ValueTotal
FROM ...
WHERE ...
GROUP BY Switch(Product Between 240 And 330, "A",
Product Between 340 And 456, "B",
Product Between 990 And 1240, "C")

If the Between doesn't work use:

Switch(240 <= Product And Product <= 330, "A",
340 <= Product And Product <= 456, "B",
990 <= Product And Product <= 1240, "C")

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQlSKMIechKqOuFEgEQI2gQCeIG/537dKVRhQ4+DWtxzWHpvD7CEAoOF0
iK43JQQ3lfl6S9DiSPGkArTl
=lvSc
-----END PGP SIGNATURE-----
green fox wrote:
In a query, a category has a number of products identified by numbers,
i.e. 240, 300, 560 etc. Each of these products can have any number of
items each with its own value. I need the sum of various groups of
products. Say products from 240 to 330, sum of the values. Sum of
values from 340 through 456, AND 990 through 1240. If there is a simple
solution that I'm just missing, please point me in the right direction.
Is it possible to do this in a simple query?

Nov 13 '05 #3
I've done next to nothing with SQL, so it took me a bit to figure out
your solution. Botton line, it worked great. Thanks for your quick
response. Can anyone recommend a source for Access Jet SQL info...where
I can learn a bit more about syntax?

Andy F.

Nov 13 '05 #4
green fox wrote:
I've done next to nothing with SQL, so it took me a bit to figure out
your solution. Botton line, it worked great. Thanks for your quick
response. Can anyone recommend a source for Access Jet SQL info...where
I can learn a bit more about syntax?


Try the Access Help. Look under the Contents tab at "Microsoft JET SQL
Reference."

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #5
Alan Webb wrote:
MGFoster,
Switch? Like TransactSQL CASE? Neat. Didn't know that was supported in
Jet SQL.


All VBA functions are usable in JET SQL.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #6

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

Similar topics

4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
2
by: BerkshireGuy | last post by:
I have the following code: Dim strSQL As String Dim DB As DAO.Database Dim RS As DAO.Recordset Dim intNumOfPaid, intNumOfHypoed, intNumOfNotTaken, intNumOfDeclined, intNumOfWasted,...
9
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with...
4
by: Micheal | last post by:
Greetings Access Group, Being relatively new to Access, I try to work through problems on my own and have been very successful, although I have a conundrum that I have been working on for two days...
5
by: colin spalding | last post by:
How do I design a totals query that instead of the following result YearOfAcc PremiumGBP 2004 9,142,306.95 2004 1,481,153.21 2005 11,981,987.85 2006 20,653,195.20 2006 ...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: 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...

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.