Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Sql question
"Shaw, John B" wrote:
>
> I want to get every date between two user entered date's whether or not it
> exists in the table and then the quantity of data for the date if any
> exists.
> My table t1 has date and quantity values (may be more than one quantity
> field per date)
> and I want 0 for all dates in the range where no data exists.
> Is there a sql to get this without making some kind of date table?
> so if the user enters 03/02/01 and 03/06/01 they get.
> 03/02/01 10
> 03/03/01 1
> 03/04/01 0
> 03/05/01 0
> 03/06/01 8
> They want to load into a spreadsheet.
> tia.
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.com
> --
> Author: Shaw, John B
> INET: jbshaw_at_ingr.com
>
> Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051
> San Diego, California -- Public Internet access / Mailing Lists
> --------------------------------------------------------------------
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from). You may
> also send the HELP command for other information (like subscribing).
John,
I wouldn't recommend something of the kind on big volumes but I guess
that if you need to load into a spreadsheet it should be OK ... It
assumes boldly that you have more columns in your schema than you need
dates, which is usually the cae.
SQL> select * from t1;
D N -------- ---------- 03/02/01 10 03/03/01 1 03/06/01 8
SQL> select t2.D, nvl(t1.N, 0)
2 from t1,
3 (select t3.minD + rownum - 1 D 4 from user_tab_columns, 5 (select min(D) minD, 6 max(D) maxD 7 from t1) t3 8 where rownum <= 1 + t3.maxD - t3.minD) t29 where t2.D = t1.D (+)
D NVL(T1.N,0)
-------- -----------
03/02/01 10 03/03/01 1 03/04/01 0 03/05/01 0 03/06/01 8
-- Regards, Stephane Faroult Oriole Corporation Voice: +44 (0) 7050-696-269 Fax: +44 (0) 7050-696-449 Performance Tools & Free Scripts -------------------------------------------------------------- http://www.oriole.com, designed by Oracle DBAs for Oracle DBAs -------------------------------------------------------------- -- Please see the official ORACLE-L FAQ: http://www.orafaq.com -- Author: Stephane Faroult INET: sfaroult_at_oriole.com Fat City Network Services -- (858) 538-5051 FAX: (858) 538-5051 San Diego, California -- Public Internet access / Mailing Lists -------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).Received on Fri Jun 29 2001 - 14:24:14 CDT