RE: Quick SQL assistance

From: Goulet, Richard <Richard.Goulet_at_parexel.com>
Date: Mon, 14 Sep 2009 16:26:38 -0400
Message-ID: <6B0D50B70F12BD41B5A67F14F5AA887F7567D6_at_us-bos-mx022.na.pxl.int>



Chris,  

    You'll need to use the mighty DECODE and MAX to help you out. Something like the following:  

select tablespace_name,

       round(max(decode(trunc(date_of_posting), trunc(sysdate),bytes_allocated))/1048576)as allocated_space,

       round(max(decode(trunc(date_of_posting), trunc(sysdate-6),bytes_allocated-bytes_used))/1048576,1)S0,

    round(max(decode(trunc(date_of_posting), trunc(sysdate-5),bytes_allocated-bytes_used))/1048576,1)S1,

    round(max(decode(trunc(date_of_posting), trunc(sysdate-4),bytes_allocated-bytes_used))/1048576,1)S2,

    round(max(decode(trunc(date_of_posting), trunc(sysdate-3),bytes_allocated-bytes_used))/1048576,1)S3,

       round(max(decode(trunc(date_of_posting), trunc(sysdate-2),bytes_allocated-bytes_used))/1048576,1)S4,

       round(max(decode(trunc(date_of_posting), trunc(sysdate-1),bytes_allocated-bytes_used))/1048576,1)S5,

       round(max(nvl(decode(trunc(date_of_posting), trunc(sysdate),bytes_allocated-bytes_used),0))/1048576,1)S6,

       round((max(decode(trunc(date_of_posting), trunc(sysdate-1),nvl(bytes_allocated-bytes_used,0),0))-

          max(decode(trunc(date_of_posting), trunc(sysdate),nvl(bytes_allocated-bytes_used,0),0)))*100/

          max(decode(trunc(date_of_posting), trunc(sysdate-1),nvl(bytes_allocated-bytes_used,bytes_allocated))),2)*-1 pct_change  

OH, don't forget the group by at the end.  

Dick Goulet
Senior Oracle DBA/NA Team Lead
PAREXEL International  


From: oracle-l-bounce_at_freelists.org
[mailto:oracle-l-bounce_at_freelists.org] On Behalf Of Taylor, Chris David Sent: Monday, September 14, 2009 4:09 PM To: 'Oracle L'
Subject: Quick SQL assistance

Ok, I'm drawing a blank here as my brain seems to hvae taken the afternoon off.  

I have a dataset:  

HOST_NAME TARGET_NAME SNAP_DATE TABLESPACE_SIZE

-------------------  ------------------------  -------------------
-----------------------------
HostA            Dev1                   9/1/2009         99,999
HostA            Dev1                   9/2/2009         99,999
HostA            Dev1                   9/3/2009         99,999

...
...
HostA            Dev2                   9/1/2009         89,999
HostA            Dev2                   9/2/2009         89,999
HostA            Dev2                   9/3/2009         89,999
 

What I need to do is come up with a query that takes the above data and ONLY shows dates of weekly intervals. I need to get the following dataset:  

(Weekly Snapshot)

HostA        Dev1        9/1/2009                 99,999
HostA        Dev1        9/8/2009                 101,999
HostA        Dev2        9/1/2009                 89,999
HostA        Dev2        9/8/2009                 91,999
 

I think I need to use an analytic function of some sort, but I cannot seem to come up with the syntax.  

Anyone have any suggestions/thoughts? (Obviously I could create another date table as a driver table and join the dates to it, but I know there's a simpler way)      

Chris Taylor
Sr. Oracle DBA
Ingram Barge Company
Nashville, TN 37205
Office: 615-517-3355
Cell: 615-354-4799
Email: chris.taylor_at_ingrambarge.com  

CONFIDENTIALITY NOTICE: This e-mail and any attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender immediately and delete the contents of this message without disclosing the contents to anyone, using them for any purpose, or storing or copying the information on any medium.  

--
http://www.freelists.org/webpage/oracle-l
Received on Mon Sep 14 2009 - 15:26:38 CDT

Original text of this message