Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
5
Erster Beitrag:
vor 4 Jahren, 6 Monaten
Letzter Beitrag:
vor 4 Jahren, 6 Monaten
Beteiligte Autoren:
stefan.kern, issah, Yogi Yang

SQL Query to sum values in one file base on another file

Startbeitrag von Yogi Yang am 04.07.2013 14:58

I am trying to build a SQL Query that will take all records in one file and sum value in another file which is linked to first file by its ID.

For Example I have two files. One is called ShirtsType which is linked to another file called ShirtOrders.

Now I want to sum the orders of shirts for all the shirt type records contained in ShirtsType file in one single Query from ShirtOrders.

Can someone help me please in doing this?

TIA

Yogi Yang

Antworten:

Not tested:


Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders Group By ShirtsType.Field1, ShirtsType,Field2

Greets

Stefan.

von stefan.kern - am 04.07.2013 16:22
Quote
stefan.kern
Not tested:


Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders Group By ShirtsType.Field1, ShirtsType,Field2

Greets

Stefan.


Correction:

Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders Group ON ShirtTypes.shirtID = ShirtOrders.ref_ShirtID By ShirtsType.Field1, ShirtsType,Field2

ShirtID and refShirtID are the linked keys.

von stefan.kern - am 04.07.2013 18:40
Quote
stefan.kern
Quote
stefan.kern
Not tested:


Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders Group By ShirtsType.Field1, ShirtsType,Field2

Greets

Stefan.


Correction:

Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders Group ON ShirtTypes.shirtID = ShirtOrders.ref_ShirtID By ShirtsType.Field1, ShirtsType,Field2

ShirtID and refShirtID are the linked keys.


ARGH:
Select ShirtsType.Field1, ShirtsType.Field2, sum(ShirtsOrders.amount) from ShirtsTypes INNER JOIN ShirtsOrders ON ShirtTypes.shirtID = ShirtOrders.ref_ShirtID Group By ShirtsType.Field1, ShirtsType,Field2

von stefan.kern - am 04.07.2013 18:42
Would have been great if you indicated how ShirtType is linked with ShirtOrders. If there is a ShirtType code in ShirtOrders and every ShirtOrder has a ShirtType then its very simple and needs no join.

select shirttype, sum(amount) from shirtorders group by shirttype.

issah

von issah - am 04.07.2013 23:46
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.