× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Try this:

SELECT custnumb,
SUM(CASE WHEN ordtype='A' then amount ELSE 0 END),
SUM(CASE WHEN ordtype='B' then quantity ELSE 0 END)
FROM <file>
WHERE <date range or other conditions>
GROUP BY custnumb

That should total the amount from records with an ordtype of "A", and the
quantity from records with an ordtype of "B".

Have fun!
Richard



-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx]On Behalf Of Tomasz Skorża
Sent: Tuesday, May 22, 2007 9:28 AM
To: midrange-l@xxxxxxxxxxxx
Subject: How to create this kind of SQL SELECT statement.


Hi

I would like to create a SELECT with diffrent criteria for fields in one
file.
I have a file with fields amount and quantity and additional fields
custnumb, ordernum, ordertype, orderdate etc.
The problem is that data for (sum of) amount and (sum of) quantity are
stored in diffrent rows. What is more complicated when row is "amount" in
field "quantity" value of weight is stored.

Next example

custnumb ordnumb ordtype orderdate amount quantity
1 1 A something 10 10
1 2 A something 20 20
1 1 B something 0 10
2 4 A something 10 15
2 4 B something 0 20
2 5 B something 0 20


And on report I would like to see (for same date range)

Custnumb amount quantity
1 30 10
2 10 40

Amount is sum of "amount" from rows A, quantity is sum of "quantity" from
rows B.
But how to write it? I created many joins but without success.

Have you any idea?

Regards

Tomasz Skorza

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.


No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.6/814 - Release Date: 5/21/2007
2:01 PM

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.467 / Virus Database: 269.7.6/814 - Release Date: 5/21/2007
2:01 PM



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.