You are here:  Home / Blog / Tags / Data Warehouse

Protect Your Data

Safe & Secure

Protecting Your DataMost people think of a “disaster” as something catastrophic and geographically widespread— an earthquake, fire, flood, or tornado, for example. Truth is, the disasters that cost global business the most don’t fit the traditional definition of catastrophe.

Contact Us

Please feel confident sending us an email, or giving us a call.contact-us
p: 403.695.1317
t: 1.855.667.1317
f: 403.770.8145
e: info@ravenbay.com
Viewing entries tagged Data Warehouse Subscribe to feed

Oracle - Difference Between Dates in Different Rows

by Mathew Bruneau
Mathew Bruneau
Guest has not set their biography yet
User is currently offline
Wednesday, 09 November 2011 Category Uncategorized 0 Comment
Ever needed to know the difference between dates within groups of rows in Oracle?
An example:  you need to calculate the processing time between status' for a given invoice:

Transaction_Table
Invoice_ID Status Time_Stamp
1 Submit 2011-01-01 7:00:00am
1 Code 2011-01-01 9:00:00am
1 Approve 2011-01-01 1:00:00pm
1 Close 2011-01-02 7:00:00am
3 Submit 2011-01-01 7:05:00am


You may be inclined to do multiple joins back to the transaction_table to get the next status and subtract the dates, ie:

Select invoice_id,

(Invoice2.time_stamp - invoice1.time_stampe) * 24 as coded_time,

(Invoice3.time_stamp – invoice2.time_stamp) * 24 as approved_time,

(Invoice4.time_stamp – invoice3.time_stamp) * 24 as closed_time

From Transaction_table invoice1

Left join Transaction_table invoice2 on invoice1.invoice_id = invoice2.invoice_id

And invoice2.status = ‘Code’

Left join Transaction_table invoice3 on invoice1.invoice_id = invoice3.invoice_id

And invoice3.status = ‘Approve’

Left join Transaction_table invoice4 on invoice1.invoice_id = invoice4.invoice_id

And invoice4.status = ‘Close’

Where invoice1.status = ‘Submit’

Invoice_ID Coded_time Approved_time Closed_time
1 2 4 18
3 Null Null null


Oracle has provided two functions that can help alleviate these unnecessary joins.  The Lead() and Lag() functions were introduced to Oracle in version 8.1.6 making this query much simpler.
The Lead() function allows us to get the next row relative to the current row and the Lag() function allows us to get the previous row relative to the current row.

LAG  (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)

LEAD (value_expression [,offset] [,default]) OVER ([query_partition_clause] order_by_clause)


We can retrieve the same information in a more normalized form allowing the query to handle more status’ as they are added (ie, multiple approvals etc) and eliminate the joins.

Select invoice_id,

status

(time_stamp - lag(time_stamp,1,null) over (partition by invoice_id order by time_stamp)) * 24 as time

from transaction_table

Invoice_id Status Time
1 Submit Null
1 Code 2
1 Approve 3
1 Close 18
3 Submit Null
Tags: Data Warehouse, Oracle, Business Analytics, Business Intelligence
Read More Hits: 460
0 vote
by Dion Dicks
Dion Dicks
http://www.ravenbay.com/company/our-team/dion-dicks.htm
User is currently offline
Friday, 04 November 2011 Category Uncategorized 1 Comment

Welcome to Las Vegas

The IBM Information On Demand conference in Las Vegas, which ran from October 23 - 28, was pouring over the sides with valuable content and opening new opportunities.  The entire conference consisted of over 700 technical education sessions, industry-focused business & IT Leadership sessions, session content featuring software, hardware and services solutions, 110 hands on labs, 300 Customer speakers, IBM's largest EXPO, complimentary certification testing, IBM and industry-renowned speakers, and more than 10,000 attendees.  So out of all of this, what managed to stick?

 

Top 3 Take Aways


1. IBM Netezza 1000: It's hardware, its software, it's a data warehouse appliance, and it’s a storage appliance ... it's all of the above!  Because the IBM Netezza 1000 data warehouse appliance comes with preconfigured software and hardware it greatly reduces the amount of effort for a company to initiate its Business Intelligence initiatives.  This system can be put in within just days rather than months, and it just runs with very little hands on tinkering required.  Check it out on netezza.com (http://www.netezza.com/data-warehouse-appliance-products/twinfin.aspx). I almost forgot the best part, it comes in three colours!


2. IBM SPSS Statistics 20: Always wanted to be a fortune teller as a kid?  With predictive analytics in your organization and expertise in IBM SPSS you'll be the resident gypsy.  IBM SPSS is based on sophisticated statistical algorithms that have been about 30 years in the making, using similar technology to that used in IBM Watson for pattern recognition, allowing the models to "learn" from the source data.  IBM SPSS can be used for predicting future revenues, production levels, consumer satisfaction levels, or detecting fraud as it happens. http://www-01.ibm.com/software/analytics/spss

 

3. Jeff Jonas Key Note: Check out Jeff's presentation here, fast foward to the 20:00 mark:  http://www.livestream.com/ibmsoftware/video?clipId=pla_7c1b7dd6-feed-4352-9cb4-2abdea9c9751&utm_source=lslibrary&utm_medium=ui-thumb.  Great puzzle analogy of how business analytics and statistical analysis can be used to mess with your kids.

 

In addition to the education sessions IOD was a great opportunity to network with current and potential clients, IBMers and business partners alike.  Raven Bay hosted a Cognos roundtable for a small group of organizations to get together where they could talk about their own issues, challenges and successes with their business intelligence initiatives.  Representatives from a broad spectrum of industries were in attendance including oil and gas, commercial airline, energy, agri-business, and online payment processing.  Representatives brought perspectives to the table from the Sr. Analyst level to IT Director level.  For an overview of the experiences provided by Petrobank Energy and Resources Ltd have a look at their recent success story, http://www-01.ibm.com/software/success/cssdb.nsf/cs/STRD-8MXGJR.  The roundtable session went over really well with lots of great feedback.  Some very useful connections were made between clients in the Calgary area as a result.

Petrobank Story

Information On Demand was a great conference with loads of applicable content, some great presenters (some not so great, but there's always a few of those), and ample opportunity to build our skill set when it comes to Cognos and business intelligence in general.

 

Check out Jeff's presentation here, fast foward to the 20:00 mark,
Tags: Business Analytics, Business Intelligence, Cognos, Data Warehouse
Read More Hits: 461
0 vote

Developed by  Late Night Tonight Live