Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to join two queries into one
Message
De
29/08/2023 02:37:04
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Visual FoxPro et .NET
Titre:
How to join two queries into one
Divers
Thread ID:
01687008
Message ID:
01687008
Vues:
46
I have invoices:

Invoice No: 10001
Discount: $30
ItemA, 2 Pcs, total $100 => net $100-$10 = $90
ItemB, 2 Pcs, total $200 => net $200-$10 = $190
ItemC, 2 Pcs, total $300 => net $300-$10 = $290
because $30 discount is distributed evenly to each item, regarding the item value and qty

Invoice No: 10002
Discount: $40
ItemA, 2 Pcs, total $100 => net $100-$20 = $80
ItemB, 2 Pcs, total $200 => net $200-$20 = $180
each item gets $20 discount, regarding the item value and qty

I expect the report as:

Group by item:
ItemA, 4 Pcs, total $170 (90+80)
ItemB, 4 Pcs, total $370 (190+180)
ItemC, 2 Pcs, total $290 (290)

so instead of this query:
select cItem,sum(nQty),sum(nAmount) from invoice group by cItem
I want to do:
select cItem,sum(nQty),sum(nAmount-nDisc/nrecord) from invoice group by cItem
where nrecord is:
select count(*) as nrecord from invoice group by cinvoice
Is that possible to do it in one query?

Thanks for the help.

Regards,

Jerry Yang
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform