Multiple tables Left Join Example

21 Jul

SELECT STAFF_ACT.STORE, STAFF_ACT.P8 AS STAFF_ACT_P8,
STAFF_ACT.P7+STAFF_ACT.P8 AS STAFF_ACT_QTD,
STAFF_ACT.P1+STAFF_ACT.P2+STAFF_ACT.P3+STAFF_ACT.P4+STAFF_ACT.P5+STAFF_ACT.P6+
STAFF_ACT.P7+STAFF_ACT.P8 AS STAFF_ACT_YTD,
STAFF_IDEAL.P8 STAFF_IDEAL_P8,
STAFF_IDEAL.P7+STAFF_IDEAL.P8 AS STAFF_IDEAL_QTD,
–YTD
STAFF_IDEAL.P1+STAFF_IDEAL.P2+STAFF_IDEAL.P3+STAFF_IDEAL.P4+STAFF_IDEAL.P5+STAFF_IDEAL.P6+
STAFF_IDEAL.P7+STAFF_IDEAL.P8 AS STAFF_IDEAL_YTD,
RET_ACT.P8 AS RET_ACT_P8,
RET_ACT.P7+RET_ACT.P8 AS RET_ACT_QTD,
–YTD
RET_ACT.P1+RET_ACT.P2+RET_ACT.P3+RET_ACT.P4+RET_ACT.P5+RET_ACT.P6+
RET_ACT.P7+RET_ACT.P8 AS RET_ACT_YTD,
RET_IDEAL.P8 AS RET_IDEAL_P8,
RET_IDEAL.P7+RET_IDEAL.P8 AS RET_IDEAL_QTD,
–YTD
RET_IDEAL.P1+RET_IDEAL.P2+RET_IDEAL.P3+RET_IDEAL.P4+RET_IDEAL.P5+RET_IDEAL.P6+
RET_IDEAL.P7+RET_IDEAL.P8 AS RET_IDEAL_YTD,
SALES_ACT.P8 AS SALES_ACT_P8,
SALES_ACT.P7+SALES_ACT.P8 AS SALES_ACT_QTD,
–YTD
SALES_ACT.P1+SALES_ACT.P2+SALES_ACT.P3+SALES_ACT.P4+SALES_ACT.P5+SALES_ACT.P6+
SALES_ACT.P7+SALES_ACT.P8 AS SALES_ACT_YTD,
FROM STAFF_ACT LEFT JOIN STAFF_IDEAL
ON STAFF_ACT.STORE = STAFF_IDEAL.STORE LEFT JOIN RET_ACT
ON STAFF_ACT.STORE = RET_ACT.STORE LEFT JOIN RET_IDEAL
ON STAFF_ACT.STORE = RET_IDEAL.STORE LEFT JOIN SALES_ACT
ON STAFF_ACT.STORE = SALES_ACT.STORE

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: