Vern Hamburg wrote on 29/05/2007 09:12:59:
Where does ordnum come from - Craig, you don't
show that field in your sample data. But assuming
it is in a related file, this solution below
looks kind of complicated and could be handled with a simple group
by, as here:
select ordnum, sum(qty)
from ordfile join transact file on ordfile.type = transact.type
group by ordnum, type
I probably should have included this as an alternative - the way the
question was phrased made me think that Craig wanted a result like this:
Ordnum PI total PR total type3 total type4 total
1 20 300 5 10
For me, the type of query I suggested has come in handy for one-time
reports. I suppose that your method + a program to run through the data
and output it nicely is the best way to accomplish this if the set of
transaction types is subject to change.
SELECT ordnum,
SUM (CASE WHEN type = 'PA' THEN qty ELSE 0 END),
SUM (CASE WHEN type = 'PI' THEN qty ELSE 0 END),
SUM (CASE WHEN type = <type3> THEN qty ELSE 0 END),
SUM (CASE WHEN type = <type4> THEN qty ELSE 0 END)
FROM ...
where <typeX> is replaced by the code for the appropriate type.
Attention:
The information contained in this message and or attachments is
intended only for the person or entity to which it is addressed and may contain
confidential and/or privileged material. Any review, retransmission,
dissemination or other use of, or taking of any action in reliance upon, this
information by persons or entities other than the intended recipient is
prohibited. If you received this message in error, please contact the sender
and
delete the material from any system and destroy any copies. Thank you for your
time and consideration.
Attention:
Le contenu de ce message et(ou) les fichiers ci-joints s?adressent
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils
peuvent
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est
strictement interdit à toute personne ou entité autre que le(la) destinataire
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de diffuser
cette information, de prendre une quelconque action en fonction ou sur la base
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message par
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message et
les fichiers ci-inclus de tout système, et en détruire toutes copies, qu?elles
soient électroniques ou imprimées. Nous vous remercions de votre entière
collaboration.
As an Amazon Associate we earn from qualifying purchases.