dimanche 22 février 2015

SQL Query to SUM data from 3 different tables

I have 3 2005 SQL tables, an order table, quote table and invoice table. Structured like this:


SO Table



Rep Code SO Amount SO Date

1 100 1/2/2015
2 50 2/15/2015
3 20 2/20/2015
2 50 2/20/2015
1 85 2/20/2015


SQ Table



Rep Code SQ Amount SQ Date

1 50 2/2/2015
2 14 2/18/2015
3 67 2/19/2015
1 96 2/20/2015
2 54 2/20/2015


INV Table



Rep Code INV Amount INV Date

1 654 2/2/2015
2 312 2/18/2015
3 54 2/19/2015
1 6 2/20/2015
3 48 2/20/2015


What I want to do is write a query which will sum up each amount by rep code, so it would look something like this:



Rep Code SO Total SQ Total Inv Total

1 185 146 660
2 100 68 312
3 20 67 102


I would also like it to only pull the totals if the appropriate date for each one is lets say in the last week. (So Today -7)


Let me know if this needs any clarification.


Aucun commentaire:

Enregistrer un commentaire