Created
August 19, 2014 14:23
-
-
Save daniilyar/9e6b41d12ee88b2b041d to your computer and use it in GitHub Desktop.
SQL2
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 FS_PERM_SEC_ID, period, avg(p_price) avg_price from ( | |
| select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'DAY' period | |
| from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and | |
| SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -1) and sysdate | |
| union all | |
| select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'WEEK' period | |
| from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and | |
| SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -7) and sysdate | |
| union all | |
| select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'MONTH' period | |
| from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and | |
| SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -30) and sysdate | |
| union all | |
| select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'QUARTER' period | |
| from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and | |
| SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -90) and sysdate | |
| union all | |
| select FS_PERM_SEC_ID, p_price, SECURITY_PRICE_DATE, 'YEAR' period | |
| from FSDF_PRICE_EOD.FP_BASIC_BD where FS_PERM_SEC_ID = 'XQC8FD-S-ES' and | |
| SECURITY_PRICE_DATE between sieve2.UTILS_PKG.add_businessdays(sysdate, -365) and sysdate | |
| ) group by FS_PERM_SEC_ID, period; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result:
XQC8FD-S-ES WEEK 7.249
XQC8FD-S-ES QUARTER 7.43192222222222222222222222222222222222
XQC8FD-S-ES DAY 7.314
XQC8FD-S-ES MONTH 7.4003
XQC8FD-S-ES YEAR 6.32793261455525606469002695417789757412