Presentation is loading. Please wait.

Presentation is loading. Please wait.

1Jonathan Lewis UKOUG Dec 2000 Analytic Functions Agenda Who am I Historical Problems The Future Questions (and answers)

Similar presentations


Presentation on theme: "1Jonathan Lewis UKOUG Dec 2000 Analytic Functions Agenda Who am I Historical Problems The Future Questions (and answers)"— Presentation transcript:

1 1Jonathan Lewis UKOUG Dec 2000 Analytic Functions Agenda Who am I Historical Problems The Future Questions (and answers)

2 2Jonathan Lewis UKOUG Dec 2000 Analytic Functions Who am I ? Independent Consultant. Design, Strategy, Briefing, Training Reviews and Trouble-shooting

3 3Jonathan Lewis UKOUG Dec 2000 Analytic Functions History For each store report the two top sellers

4 4Jonathan Lewis UKOUG Dec 2000 Analytic Functions History create table game_sale ( titlevarchar2(20), storevarchar2(10), salesnumber(10,2) );

5 5Jonathan Lewis UKOUG Dec 2000 Analytic Functions History ('Portal Combat', 'London', 1824); ('Manic the Gerbil', 'London', 52); ('Age of Umpires', 'London', 110); ('Crash Simulator', 'London', 247); ('Dome', 'London', 2167);

6 6Jonathan Lewis UKOUG Dec 2000 Analytic Functions History select store, title, sales from game_sale order by store, sales desc

7 7Jonathan Lewis UKOUG Dec 2000 Analytic Functions History Glasgow Crash Simulator 1934 Manic the Gerbil 913 Dome 482 Portal Combat 315 Age of Umpires 72 London Dome 2167 Portal Combat 1824 Crash Simulator 247 Age of Umpires 110 Manic the Gerbil 52

8 8Jonathan Lewis UKOUG Dec 2000 Analytic Functions History declare cursor c1 is select store, title, sales fromgame_sale order by store, sales desc ; m_last_row c1%rowtype; m_out_ctnumber := 0; begin do something... end;

9 9Jonathan Lewis UKOUG Dec 2000 Analytic Functions History for r1 in c1 loop if (m_last_row.store != r1.store) then m_out_ct := 0; dbms_output.new_line; end if; if m_out_ct != 2 then dbms_output.put_line ( r1.store || ' - ' || r1.title || ' - ' || r1.sales ); m_out_ct := m_out_ct + 1; end if; m_last_row := r1; end loop;

10 10Jonathan Lewis UKOUG Dec 2000 Analytic Functions History Glasgow - Crash Simulator Glasgow - Manic the Gerbil London - Dome London - Portal Combat

11 11Jonathan Lewis UKOUG Dec 2000 Analytic Functions History ('Portal Combat', 'London', 1824); ('Manic the Gerbil', 'London', 52); ('Age of Umpires', 'London', 110); ('Crash Simulator', 'London', 1824); ('Dome', 'London', 2167);

12 12Jonathan Lewis UKOUG Dec 2000 Analytic Functions History selectstore, title, sales fromgame_sale gs1 where2 > ( selectcount(*) fromgame_sale gs2 wheregs2.store = gs1.store andgs2.sales > gs1.sales ) order by store, sales desc;

13 13Jonathan Lewis UKOUG Dec 2000 Analytic Functions History STORE TITLE SALES Glasgow Crash Simulator 1934 Manic the Gerbil 913 London Dome 2167 Portal Combat 1824

14 14Jonathan Lewis UKOUG Dec 2000 Analytic Functions History ('Portal Combat', 'London', 1824); ('Manic the Gerbil', 'London', 52); ('Age of Umpires', 'London', 110); ('Crash Simulator', 'London', 1824); ('Dome', 'London', 2167); where2 > ( selectcount(*)

15 15Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future. select store, title, sales, rank() over ( partition by store order by sales desc ) as in_store_rank from game_sale ;

16 16Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future Glasgow Crash Simulator Manic the Gerbil Dome Portal Combat Age of Umpires 72 5 London Dome Portal Combat Crash Simulator Age of Umpires Manic the Gerbil 52 5

17 17Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future select store, title, sales from(selectstore, title, sales, rank() over ( partition by store order by sales desc ) as in_store_rank from game_sale ) wherein_store_rank <= 2 order bystore, in_store_rank;

18 18Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future STORE TITLE SALES Glasgow Crash Simulator 1934 Tonic the Gerbil 913 London Dome 2167 Portal Combat 1824

19 19Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future select store, title, sales from(select store, title, sales, rank() over ( partition by store order by sales desc ) as in_store_rank, sum(sales) over ( partition by store ) as store_totals fromgame_sale) wherein_store_rank <= 2 order bystore_totals desc, in_store_rank;

20 20Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future STORE TITLE SALES London Dome 2167 Portal Combat 1824 Glasgow Crash Simulator 1934 Tonic the Gerbil 913

21 21Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future AVGSUM** COUNT MAXMIN RANK** ROW_NUMBER DENSE_RANKPERCENT_RANK

22 22Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future RATIO_TO_REPORT LEADLAG FIRST_VALUELAST_VALUE NTILECUME_DIST

23 23Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future VARIANCESTDDEV CORR VAR_POPVAR_SAMP COVAR_POPCOVAR_SAMP STDDEV_POP STDDEV_SAMP REGR_ (linear regression function)

24 24Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future Title Sales Previous Delta Crash Simulator Tonic the Gerbil Dome Portal Combat Age of Umpires 72

25 25Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future selecttitle, sales, previous, this_sale - next_sale delta from ( selecttitle, sales, lead(sales,1) over ( partition by store order by sales desc ) as previous from game_sale );

26 26Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future Store Title Sale St % Co % Glasgow Crash Simulator Tonic the Gerbil Dome Portal Combat Age of Umpires London Dome Portal Combat Crash Simulator Age of Umpires Tonic the Gerbil

27 27Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future selectstore, title, sales, ratio_to_report(sales) over ( partition by store )store_ratio, ratio_to_report(sales) over ( )country_ratio fromgame_sale order by store, sales desc;

28 28Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future StoreWeek EndingSalesRolling Glasgow07-May-20004,0005, May-20005,0005, May-20006,0006, May-20007,0006, Jun-20008,0007, Jun-20007,8027, Jun-20007,6367, Jun-20008,1347, Jul-20007,8157, Jul-20008,0237,990.7

29 29Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future select store, week_ending, sales, avg(sales) over( partition by store order by week_ending range between 14 preceding and 14 following )rolling_5 from sales_history order by store, week_ending;

30 30Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future StoreWeek EndingSalesRunning Glasgow07-May-20004,000 4, May-20005,000 9, May-20006,000 15, May-20007,000 22, Jun-20008,000 30, Jun-20007,802 37, Jun-20007,636 45, Jun-20008,134 53,572 2-Jul-20007,815 61,387 9-Jul-20008,023 69,410

31 31Jonathan Lewis UKOUG Dec 2000 Analytic Functions The Future select store, week_ending, sales, avg(sales) over( partition by store order by week_ending range unbounded preceding )running from sales_history order by store, week_ending;

32 32Jonathan Lewis UKOUG Dec 2000 Analytic Functions Warnings Lots of sorting. Use only on small result sets pl/sql doesn’t understand it can’t often use view effectively

33 33Jonathan Lewis UKOUG Dec 2000 Analytic Functions Conclusion Enormously powerful Use in-line views to make it easy


Download ppt "1Jonathan Lewis UKOUG Dec 2000 Analytic Functions Agenda Who am I Historical Problems The Future Questions (and answers)"

Similar presentations


Ads by Google