Created
March 30, 2016 16:23
-
-
Save phpdave/da2d049559afd31f414e4fcacb0d4de6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| a.KEY1, | |
| a.KEY2, | |
| SUM(COALESCE (TOTAL_FIELD3,0)) AS TOTAL_FIELD3, | |
| SUM(COALESCE (TOTAL_FIELD4,0)) AS TOTAL_FIELD4 | |
| FROM | |
| TABLE1 a | |
| LEFT JOIN | |
| (SELECT | |
| SUM(FIELD3) AS TOTAL_FIELD3, | |
| T1KEY | |
| FROM | |
| TABLE2 | |
| WHERE | |
| MYDATEFIELD <= PARM1 | |
| GROUP BY | |
| T1KEY ) b | |
| ON | |
| a.T1KEY=b.T1KEY | |
| LEFT JOIN | |
| (SELECT | |
| SUM(FIELD4) AS TOTAL_FIELD4, | |
| T1KEY | |
| FROM | |
| TABLE2 | |
| WHERE | |
| MYDATEFIELD >= PARM2 AND | |
| MYDATEFIELD <= PARM1 | |
| GROUP BY | |
| T1KEY ) c | |
| ON | |
| a.T1KEY=c.T1KEY | |
| GROUP BY KEY1,KEY2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment