ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  SQL Subqueries
Subject:   Subquery
Date:   2003-06-21 03:17:00
From:   anonymous2
I would like to combine the following two queries in one, how please?


SELECT
AS_OF_DATE,
SERIES_NAME,


AVG(VALUE) OVER (PARTITION BY SERIES_NAME ORDER BY AS_OF_DATE ASC ROWS 4 PRECEDING) MOVING_AVG_5_DAY



FROM V_DBO_VALUE
WHERE PERIOD = 'D' AND
SERIES_NAME IN ('WTIMARK', 'DUBAI') AND
AS_OF_DATE > TO_DATE('20030501', 'YYYYMMDD')



The second query is:
SELECT
AS_OF_DATE,
SOURCE.PERIOD,
SUM(DECODE(TRIM(SERIES_NAME), 'WTIMARK', VALUE, NULL)) MWTI
SUM(DECODE(TRIM(SERIES_NAME), 'DUBAIM', VALUE, NULL)) MDUBAI


FROM V_DBO_VALUE
WHERE
SERIES NAME IN ('WTIMARK', 'DUBAI') AND
SOURCE.PERIOD='D'


GROUP BY AS_OF_DATE, PERIOD