16
SQL Tips & Tricks Getting more done with SQL DML statements Lannois Carroll-Woolery, IST

SQL Tips & Tricks

  • Upload
    carney

  • View
    67

  • Download
    0

Embed Size (px)

DESCRIPTION

SQL Tips & Tricks. Getting more done with SQL DML statements. Lannois Carroll-Woolery, IST. Disclaimers. “This isn’t what I expected…” “I know a better way...” “It worked when you did it…”. Useful DML Techniques. Conditional logic Crosstab reports Running Totals - PowerPoint PPT Presentation

Citation preview

Page 1: SQL Tips & Tricks

SQL Tips & Tricks

Getting more done with SQL DML statements

Lannois Carroll-Woolery, IST

Page 2: SQL Tips & Tricks

Disclaimers• “This isn’t what I expected…”

• “I know a better way...”

• “It worked when you did it…”

2010 | The Sky’s the Limit

Page 3: SQL Tips & Tricks

Useful DML Techniques• Conditional logic• Crosstab reports• Running Totals• Generating a list of dates• Counting the number of working days• Generating date ranges from Eff. Dates• Histograms• Hierarchical Queries

2010 | The Sky’s the Limit

Page 4: SQL Tips & Tricks

Round the World Itinerary

2010 | The Sky’s the Limit

Page 5: SQL Tips & Tricks

Table PS_FLIGHTS

LEG DEPARTURE_CITY DEPARTURE_DATETIME ARRIVAL_CITY ARRIVAL_DATETIME AIRLINE FLIGHT_NO MILES

01 Toronto 06/29/2011 19:10:00 Ottawa 06/29/2011 20:10:00 Air Canada AC 464 233

02 Ottawa 07/02/2011 15:10:00 New York 07/02/2011 16:42:00 Continental CO 2623 331

03 New York 07/06/2011 21:10:00 London 07/07/2011 09:25:00 Continental CO 112 3,458

04 London 07/13/2011 17:05:00 Frankfurt 07/13/2011 19:35:00 Lufthansa LH 911 396

05 Frankfurt 07/13/2011 20:35:00 Paris 07/13/2011 21:45:00 Lufthansa LH 1050 275

06 Paris 07/16/2011 18:35:00 Zurich 07/16/2011 19:45:00 SwissAir LX 657 291

07 Zurich 07/20/2011 09:45:00 Cairo 07/20/2011 14:40:00 SwissAir LX 236 1,705

08 Cairo 07/24/2011 10:00:00 Dubai 07/24/2011 14:45:00 EgyptAir MS 912 1,499

09 Dubai 08/03/2011 00:10:00 Beijing 08/03/2011 11:45:00 Air China CA 942 3,646

10 Beijing 08/03/2011 13:25:00 Tokyo 08/03/2011 18:00:00 Air China CA 167 1,313

11 Tokyo 08/10/2011 17:40:00 San Francisco 08/10/2011 10:56:00 United UA 852 5,130

12 San Francisco 08/14/2011 21:50:00 Toronto 08/15/2011 05:43:00 Air Canada AC 754 2,254

2010 | The Sky’s the Limit

Page 6: SQL Tips & Tricks

“What currencies will I need?”Conditional Logic

2010 | The Sky’s the Limit

Page 7: SQL Tips & Tricks

“What days of the week will I fly?”Crosstab reports

2010 | The Sky’s the Limit

Page 8: SQL Tips & Tricks

“How many miles have I travelled so far?” Running Totals

2010 | The Sky’s the Limit

Page 9: SQL Tips & Tricks

“Can I make a detailed itinerary?”Generating a list of dates

2010 | The Sky’s the Limit

Page 10: SQL Tips & Tricks

“How many Vacation Days do I need?”Calc. Elapsed Working Days

2010 | The Sky’s the Limit

Page 11: SQL Tips & Tricks

“What dates will I be in each country?”Date Ranges from Effective-Dated tables

2010 | The Sky’s the Limit

Page 12: SQL Tips & Tricks

“I only like afternoon flights…”Histograms

2010 | The Sky’s the Limit

Page 13: SQL Tips & Tricks

“I need my manager’s boss’ approval…”Hierarchical Queries 1/2

2010 | The Sky’s the Limit

Page 14: SQL Tips & Tricks

“I’m going over his/her head…”Hierarchical Queries 2/2

2010 | The Sky’s the Limit

Page 15: SQL Tips & Tricks

Questions?• Conditional logic• Crosstab reports• Running Totals• Generating a list of dates• Counting the number of working days• Generating date ranges from Eff. Dates• Histograms• Hierarchical Queries

2010 | The Sky’s the Limit

Page 16: SQL Tips & Tricks

References• http://www.oracle.com/technetwork/issue-archive/index-093676.html• http://www.oracle.com/pls/db102/portal.all_books#index-SQL• http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_code_a_matrix.2Fcrosstab.2

Fpivot_report_in_SQL.3F• http://consultingblogs.emc.com/jamespipe/archive/2007/01/15/Oracle-SQL-_2D00_-G

enerate-a-list-of-dates.aspx• http://www.orafaq.com/node/55• Money Sense magazine. September/October 2010

2010 | The Sky’s the Limit