SlideShare a Scribd company logo
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How to Find Patterns in Your Data with SQL
Chris Saxon, @ChrisRSaxon & @SQLDaily
blogs.oracle.com/sql
youtube.com/c/TheMagicofSQL
asktom.oracle.com
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Safe Harbor Statement
The following is intended to outline our general product direction. It is intended for
information purposes only, and may not be incorporated into any contract. It is not a
commitment to deliver any material, code, or functionality, and should not be relied upon
in making purchasing decisions. The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole discretion of Oracle.
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
This presentation contains <regular expressions>!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | blogs.oracle.com/sql www.youtube.com/c/TheMagicOfSQL @ChrisRSaxon
I thought
this was
about SQL!
Ryan McGuire / Gratisography
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
* => zero or more matches
+ => one or more matches
{n,m} => N through M matches
(either optional)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Am I Improving?
Can Beat My PB?
Am I Training Regularly?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Am I running
every day?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
#1
#3
#2
#4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How I know if rows are consecutive?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current value = previous value + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
lag ( run_date ) over
( order by run_date )
Get the previous row's date
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE RN TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 1 420 1
02 Jan 2018 2 2,400 5
03 Jan 2018 3 4,932 10
06 Jan 2018 4 2,350 5
07 Jan 2018 5 410 1
10 Jan 2018 6 400 1
13 Jan 2018 7 2,300 5
14 Jan 2018 8 425 1
15 Jan 2018 9 422 1
consecutive =>
constant gap
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE RN TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 1 420 1
02 Jan 2018 2 2,400 5
03 Jan 2018 3 4,932 10
06 Jan 2018 4 2,350 5
07 Jan 2018 5 410 1
10 Jan 2018 6 400 1
13 Jan 2018 7 2,300 5
14 Jan 2018 8 425 1
15 Jan 2018 9 422 1
-
-
-
-
-
-
-
-
-
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE RN RUN_DATE - RN TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 1 31 Dec 2017 420 1
02 Jan 2018 2 31 Dec 2017 2,400 5
03 Jan 2018 3 31 Dec 2017 4,932 10
06 Jan 2018 4 02 Jan 2018 2,350 5
07 Jan 2018 5 02 Jan 2018 410 1
10 Jan 2018 6 04 Jan 2018 400 1
13 Jan 2018 7 06 Jan 2018 2,300 5
14 Jan 2018 8 06 Jan 2018 425 1
15 Jan 2018 9 06 Jan 2018 422 1
-
-
-
-
-
-
-
-
-
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE RN RUN_DATE - RN TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 1 31 Dec 2017 420 1
02 Jan 2018 2 31 Dec 2017 2,400 5
03 Jan 2018 3 31 Dec 2017 4,932 10
06 Jan 2018 4 02 Jan 2018 2,350 5
07 Jan 2018 5 02 Jan 2018 410 1
10 Jan 2018 6 04 Jan 2018 400 1
13 Jan 2018 7 06 Jan 2018 2,300 5
14 Jan 2018 8 06 Jan 2018 425 1
15 Jan 2018 9 06 Jan 2018 422 1
-
-
-
-
-
-
-
-
-
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tabibitosan Method
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
row_number ()
over ( order by run_date )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
run_date -
row_number ()
over ( order by run_date ) grp
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with grps as (
select run_date ,
run_date -
row_number ()
over ( order by run_date ) grp
from running_log r
)
select min ( run_date ), count (*)
from grps
group by grp
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
12c Pattern Matching
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
this = prev + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
this = prev + 1
this = prev + 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
this = prev + 1
this = prev + 3
this ≠ prev + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
define
consecutive as
run_date = prev ( run_date ) + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
"Always true"
> 0 matches
Any row <>
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE VARIABLE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 STRT 420 1
02 Jan 2018 CONSECUTIVE 2,400 5
03 Jan 2018 CONSECUTIVE 4,932 10
06 Jan 2018 STRT 2,350 5
07 Jan 2018 CONSECUTIVE 410 1
10 Jan 2018 STRT 400 1
13 Jan 2018 STRT 2,300 5
14 Jan 2018 CONSECUTIVE 425 1
15 Jan 2018 CONSECUTIVE 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
Which row is prev?!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
order by run_date
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
);
How many consecutive rows?
From first row in group
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
START_DATE DAYS
01 Jan 2018 3
06 Jan 2018 2
10 Jan 2018 1
13 Jan 2018 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
So which is
better?
Pixabay
pattern
matching
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Performance ~ similar
Availability MR 12c vs 8i*
Readability personal pref
Match_recognize vs. Tabibitosan
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Am I running >= 3
times/week?
Pixabay
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How I know if runs are in the same week?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
last Monday = prev last Monday
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
trunc ( run_date , 'iw' )
Return the start of the ISO week…
…Monday!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TRUNC(RUN_DATE, 'IW') TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 Jan 2018 420 1
02 Jan 2018 01 Jan 2018 2,400 5
03 Jan 2018 01 Jan 2018 4,932 10
06 Jan 2018 01 Jan 2018 2,350 5
07 Jan 2018 01 Jan 2018 410 1
10 Jan 2018 08 Jan 2018 400 1
13 Jan 2018 08 Jan 2018 2,300 5
14 Jan 2018 08 Jan 2018 425 1
15 Jan 2018 15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select trunc ( run_date , 'iw' ),
count(*)
from running_log
group by trunc ( run_date , 'iw' )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select trunc ( run_date , 'iw' ),
count(*)
from running_log
group by trunc ( run_date , 'iw' )
having count (*) >= 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
12c Pattern Matching
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
define
same_week as
trunc ( run_date, 'iw' ) =
prev ( trunc ( run_date, 'iw' ) )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( strt same_week* )
define
same_week as
trunc ( run_date, 'iw' ) =
prev ( trunc ( run_date, 'iw' ) )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( strt same_week {2, } )
define
same_week as
trunc ( run_date, 'iw' ) =
prev ( trunc ( run_date, 'iw' ) )
);
Two or more matches
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( strt same_week {2, } )
define
same_week as
trunc ( run_date, 'iw' ) =
prev ( trunc ( run_date, 'iw' ) )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( strt consecutive* )
define
consecutive as
run_date = prev ( run_date ) + 1
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How I can I find consecutive weeks
with >= 3 runs?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Find weeks >= 3 runs
then
check these are consecutive!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with min_three_runs as (
select * from running_log
match_recognize (
order by run_date
measures
first ( trunc ( run_date, 'iw' ) )
as week_start,
count(*) as days
pattern ( strt same_week {2, } )
define
same_week as
trunc ( run_date, 'iw' ) =
prev ( trunc ( run_date, 'iw' ) )
)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How I can I find consecutive weeks?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current Monday = prev Monday + 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tabibitosan Method
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
WEEK_START RN WEEK_START – RN RUNS
01 Jan 2018 1 31 Dec 2017 5
08 Jan 2018 2 06 Jan 2018 3
15 Jan 2018 3 12 Jan 2018 4
05 Feb 2018 4 01 Feb 2018 3
12 Feb 2018 5 07 Feb 2018 3
05 Mar 2018 6 28 Feb 2018 3
12 Mar 2018 7 07 Mar 2018 4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Tabibitosan Method
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
WEEK_START RN * 7 RUNS
01 Jan 2018 7 5
08 Jan 2018 14 3
15 Jan 2018 21 4
05 Feb 2018 28 3
12 Feb 2018 35 3
05 Mar 2018 42 3
12 Mar 2018 49 4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
WEEK_START RN * 7 WEEK_START – ( RN * 7 ) RUNS
01 Jan 2018 7 25 Dec 2017 5
08 Jan 2018 14 25 Dec 2017 3
15 Jan 2018 21 25 Dec 2017 4
05 Feb 2018 28 08 Jan 2018 3
12 Feb 2018 35 08 Jan 2018 3
05 Mar 2018 42 22 Jan 2018 3
12 Mar 2018 49 22 Jan 2018 4
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select run_date - ( 7 *
row_number()
over ( order by run_date )
) grp
from min_three_runs
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by week_start
measures
first ( week_start ) as start_date,
count (*) as weeks
pattern ( strt consecutive_weeks* )
define
consecutive_weeks as
week_start = prev ( week_start ) + 7
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Pixabay
Am I running >= 3
times in 7 days?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current day < first day + 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
#1
#2
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 – 07 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 08 – 14 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 15 – 21 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 – 07 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 08 – 14 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 15 – 21 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 – 07 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 2,350 5
07 Jan 2018 410 1
10 Jan 2018 10 – 17 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select r.*, min ( run_date ) over (
order by run_date
) mn_date
from running_log r
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 Jan 2018 420 1
02 Jan 2018 01 Jan 2018 2,400 5
03 Jan 2018 01 Jan 2018 4,932 10
06 Jan 2018 01 Jan 2018 2,350 5
07 Jan 2018 01 Jan 2018 410 1
10 Jan 2018 01 Jan 2018 400 1
13 Jan 2018 01 Jan 2018 2,300 5
14 Jan 2018 01 Jan 2018 425 1
15 Jan 2018 01 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Windowing clause to the rescue…
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select r.*, min ( run_date ) over (
order by run_date
range between 7 preceding
and current row
) mn_date
from running_log r
Consider rows with values
in the previous 7 days
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 Jan 2018 420 1
02 Jan 2018 01 Jan 2018 2,400 5
03 Jan 2018 01 Jan 2018 4,932 10
06 Jan 2018 01 Jan 2018 2,350 5
07 Jan 2018 01 Jan 2018 410 1
10 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 Jan 2018 420 1
02 Jan 2018 01 Jan 2018 2,400 5
03 Jan 2018 01 Jan 2018 4,932 10
06 Jan 2018 01 Jan 2018 2,350 5
07 Jan 2018 01 Jan 2018 410 1
10 Jan 2018 03 Jan 2018 400 1
13 Jan 2018 2,300 5
14 Jan 2018 425 1
15 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 01 Jan 2018 420 1
02 Jan 2018 01 Jan 2018 2,400 5
03 Jan 2018 01 Jan 2018 4,932 10
06 Jan 2018 01 Jan 2018 2,350 5
07 Jan 2018 01 Jan 2018 410 1
10 Jan 2018 03 Jan 2018 400 1
13 Jan 2018 06 Jan 2018 2,300 5
14 Jan 2018 07 Jan 2018 425 1
15 Jan 2018 10 Jan 2018 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Windowing clause to the rescue!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
11.2 Recursive With
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with rws as (
select r.*, row_number() over ( order by run_date ) rn
from running_log r
)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with rws as (
select r.*, row_number() over ( order by run_date ) rn
from running_log r
), within_7 (
run_date, time_in_s, distance_in_miles, rn, grp_start
) as (
select run_date, time_in_s, distance_in_miles, rn, run_date grp_start
from rws
where rn = 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with rws as (
select r.*, row_number() over ( order by run_date ) rn
from running_log r
), within_7 (
run_date, time_in_s, distance_in_miles, rn, grp_start
) as (
select run_date, time_in_s, distance_in_miles, rn, run_date grp_start
from rws
where rn = 1
union all
select r.run_date, r.time_in_s, r.distance_in_miles, r.rn,
from within_7 w
join rws r
on w.rn + 1 = r.rn
)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with rws as (
select r.*, row_number() over ( order by run_date ) rn
from running_log r
), within_7 (
run_date, time_in_s, distance_in_miles, rn, grp_start
) as (
select run_date, time_in_s, distance_in_miles, rn, run_date grp_start
from rws
where rn = 1
union all
select r.run_date, r.time_in_s, r.distance_in_miles, r.rn,
case
when r.run_date < w.grp_start + 7 then grp_start
else r.run_date
end grp_start
from within_7 w
join rws r
on w.rn + 1 = r.rn
)
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
with rws as (
select r.*, row_number() over ( order by run_date ) rn
from running_log r
), within_7 (
run_date, time_in_s, distance_in_miles, rn, grp_start
) as (
select run_date, time_in_s, distance_in_miles, rn, run_date grp_start
from rws
where rn = 1
union all
select r.run_date, r.time_in_s, r.distance_in_miles, r.rn,
case
when r.run_date < w.grp_start + 7 then grp_start
else r.run_date
end grp_start
from within_7 w
join rws r
on w.rn + 1 = r.rn
)
select grp, w.*
from within_7 w
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
10g Model
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select * from running_log
model
dimension by ( row_number() over ( order by run_date ) rn )
measures ( run_date, 1 grp, run_date grp_start )
rules (
grp_start[1] = run_date[cv()],
grp_start[any] =
case
when run_date[cv()] < grp_start[cv()-1] + 7 then
grp_start[cv() - 1]
else run_date[cv()]
end ,
grp[any] =
case
when run_date[cv()] < grp_start[cv()-1] + 7 then
grp[cv() - 1]
else nvl(grp[cv() - 1] + 1, 1)
end
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
12c Pattern Matching
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current day < first day + 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
define
within7 as
run_date < first ( run_date ) + 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( within7+ )
define
within7 as
run_date < first ( run_date ) + 7
> 1 matches
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as days
pattern ( within7+ )
define
within7 as
run_date < first ( run_date ) + 7
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Am I getting
faster? stocksnap.io
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current time < prev time
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Analytic Functions
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
lag ( time_in_s )
over ( order by run_date )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
select r.*, case
when time_in_s <
lag ( time_in_s )
over ( order by run_date )
then 'FASTER'
else 'SLOWER'
end faster
from running_log r
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
12c Pattern Matching
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
current time < prev time
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
define
faster as
time_in_s < prev ( time_in_s )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( slower faster* )
define
faster as
time_in_s < prev ( time_in_s )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
classifier () as faster
pattern ( slower faster* )
define
faster as
time_in_s < prev ( time_in_s )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
FASTER
SLOWER
SLOWER
FASTER
FASTER
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
classifier () as faster
one row per match
pattern ( slower faster* )
define
faster as
time_in_s < prev ( time_in_s )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
classifier () as faster
all rows per match
pattern ( slower faster* )
define
faster as
time_in_s < prev ( time_in_s )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 SLOWER 420 1
02 Jan 2018 SLOWER 2,400 5
03 Jan 2018 SLOWER 4,932 10
06 Jan 2018 FASTER 2,350 5
07 Jan 2018 FASTER 410 1
10 Jan 2018 FASTER 400 1
13 Jan 2018 SLOWER 2,300 5
14 Jan 2018 FASTER 425 1
15 Jan 2018 FASTER 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 SLOWER 420 1
02 Jan 2018 SLOWER 2,400 5
03 Jan 2018 SLOWER 4,932 10
06 Jan 2018 FASTER 2,350 5
07 Jan 2018 FASTER 410 1
10 Jan 2018 FASTER 400 1
13 Jan 2018 SLOWER 2,300 5
14 Jan 2018 FASTER 425 1
15 Jan 2018 FASTER 422 1
SLOWER!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
07 Jan 2018 410 1
10 Jan 2018 400 1
14 Jan 2018 425 1
15 Jan 2018 422 1
02 Jan 2018 2,400 5
06 Jan 2018 2,350 5
13 Jan 2018 2,300 5
03 Jan 2018 4,932 10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
partition by distance_in_miles
order by run_date
measures
classifier () as faster
all rows per match
pattern ( slower faster* )
define
faster as
time_in_s < prev ( time_in_s )
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 SLOWER 420 1
07 Jan 2018 FASTER 410 1
10 Jan 2018 FASTER 400 1
14 Jan 2018 SLOWER 425 1
15 Jan 2018 FASTER 422 1
02 Jan 2018 SLOWER 2,400 5
06 Jan 2018 FASTER 2,350 5
13 Jan 2018 FASTER 2,300 5
03 Jan 2018 SLOWER 4,932 10
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Can I run 10k in
< 50 minutes?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Sum the total distance for runs
with a total time < 50 minutes
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
cumulative time <= 3,000 seconds
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( fifty_minutes+ )
define
fifty_minutes as
sum ( time_in_s ) <= 3000
Returns the running total
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as strt ,
sum ( time_in_s ) as total_time,
sum ( distance_in_miles ) as dist
pattern ( fifty_minutes+ )
define
fifty_minutes as
sum ( time_in_s ) <= 3000
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
STRT TOTAL_TIME DIST
01 Jan 2018 2,820 6
06 Jan 2018 2,760 6
10 Jan 2018 2,700 6
14 Jan 2018 847 2
Where's my 10 mile run?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
any runs cumulative time < 3,000
and
one run cumulative time >= 3,000
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( under_fifty* over_fifty )
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( under_fifty* over_fifty )
define
under_fifty as
sum ( time_in_s ) < 3000,
over_fifty as
sum ( time_in_s ) >= 3000
);
Includes under_fifty values
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as strt ,
sum ( time_in_s ) as total_time,
sum ( distance_in_miles ) as dist
pattern ( under_fifty* over_fifty )
define
under_fifty as
sum ( time_in_s ) < 3000,
over_fifty as
sum ( time_in_s ) >= 3000
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
STRT TOTAL_TIME DIST
01 Jan 2018 7,752 16
06 Jan 2018 3,160 7
13 Jan 2018 3,147 7
Hmmm….
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as strt ,
sum ( time_in_s ) as total_time,
sum ( distance_in_miles ) as dist
after match skip past last row
pattern ( under_fifty* over_fifty )
define
under_fifty as
sum ( time_in_s ) < 3000,
over_fifty as
sum ( time_in_s ) >= 3000
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as strt ,
sum ( time_in_s ) as total_time,
sum ( distance_in_miles ) as dist
after match skip to next row
pattern ( under_fifty* over_fifty )
define
under_fifty as
sum ( time_in_s ) < 3000,
over_fifty as
sum ( time_in_s ) >= 3000
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
STRT TOTAL_TIME DIST
01 Jan 2018 7,752 16
02 Jan 2018 7,332 15
03 Jan 2018 4,932 10
06 Jan 2018 3,160 7
07 Jan 2018 3,110 7
10 Jan 2018 3,125 7
13 Jan 2018 3,147 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Pixabay
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How often did I run 5 miles
Followed by 2+ 1 mile runs
Within 7 days?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( five_mile one_mile {2,} )
define
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( five_mile one_mile {2,} )
define
five_mile as distance_in_miles = 5,
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( five_mile one_mile {2,} )
define
five_mile as distance_in_miles = 5,
one_mile as distance_in_miles = 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
pattern ( five_mile one_mile {2,} )
define
five_mile as distance_in_miles = 5,
one_mile as distance_in_miles = 1
and run_date < first ( run_date ) + 7
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
first ( run_date ) as start_date,
count (*) as total_runs
pattern ( five_mile one_mile {2,} )
define
five_mile as distance_in_miles = 5,
one_mile as distance_in_miles = 1
and run_date < first ( run_date ) + 7
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
STRT TOTAL_RUNS
06 Jan 2018 3
13 Jan 2018 3
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Why would I want to do that?!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Pixabay
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
How do
I debug it?
Gratisography
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
(Regular) [exprsion]+ are easy to missteak
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
regex101.comregex101.com
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
classifier
=> Which variable matched?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
classifier
=> Which variable matched?
match_number
=> Which group is this?
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
classifier
=> Which variable matched?
match_number
=> Which group is this?
all rows per match
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
classifier
=> Which variable matched?
match_number
=> Which group is this?
all rows per match with unmatched rows
=> Show me everything!
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
match_recognize (
order by run_date
measures
classifier () as var,
match_number () as grp
all rows per match with unmatched rows
pattern ( five_mile one_mile {2,} )
define
five_mile as distance_in_miles = 5,
one_mile as distance_in_miles = 1
and run_date < first ( run_date ) + 7
);
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
RUN_DATE VAR GRP TIME_IN_S DISTANCE_IN_MILES
01 Jan 2018 420 1
02 Jan 2018 2,400 5
03 Jan 2018 4,932 10
06 Jan 2018 FIVE_MILE 1 2,350 5
07 Jan 2018 ONE_MILE 1 410 1
10 Jan 2018 ONE_MILE 1 400 1
13 Jan 2018 FIVE_MILE 2 2,300 5
14 Jan 2018 ONE_MILE 2 425 1
15 Jan 2018 ONE_MILE 2 422 1
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Want more?
Pixabay
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
iTunes & PDF
FREE!
SQL for Data Warehousing and Analytics
https://oracle-big-data.blogspot.co.uk
Keith Laker
Analytic SQL PM
Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Gratisography
#MakeDataGreatAgain
oracle-big-data.blogspot.co.uk

More Related Content

What's hot

Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
Simon Huang
 
TFA Collector - what can one do with it
TFA Collector - what can one do with it TFA Collector - what can one do with it
TFA Collector - what can one do with it
Sandesh Rao
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
Guy Harrison
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Tanel Poder
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
Mohamed Farouk
 
Apache Solr Workshop
Apache Solr WorkshopApache Solr Workshop
Apache Solr Workshop
Saumitra Srivastav
 
Oracle 表格介紹
Oracle 表格介紹Oracle 表格介紹
Oracle 表格介紹
Chien Chung Shen
 
Scaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ssScaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ss
Anil Nair
 
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Sandesh Rao
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
Kyle Hailey
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
Carlos Sierra
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
OOUG: Oracle transaction locking
OOUG: Oracle transaction lockingOOUG: Oracle transaction locking
OOUG: Oracle transaction locking
Kyle Hailey
 
JSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in DatabaseJSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in Database
Steven Feuerstein
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
Mohamed Farouk
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
Zohar Elkayam
 
Oracle Database Management - Backup/Recovery
Oracle Database Management - Backup/RecoveryOracle Database Management - Backup/Recovery
Oracle Database Management - Backup/Recovery
Chien Chung Shen
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Carlos Sierra
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
Enkitec
 

What's hot (20)

Oracle db performance tuning
Oracle db performance tuningOracle db performance tuning
Oracle db performance tuning
 
TFA Collector - what can one do with it
TFA Collector - what can one do with it TFA Collector - what can one do with it
TFA Collector - what can one do with it
 
Oracle sql high performance tuning
Oracle sql high performance tuningOracle sql high performance tuning
Oracle sql high performance tuning
 
Troubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contentionTroubleshooting Complex Performance issues - Oracle SEG$ contention
Troubleshooting Complex Performance issues - Oracle SEG$ contention
 
Understanding oracle rac internals part 1 - slides
Understanding oracle rac internals   part 1 - slidesUnderstanding oracle rac internals   part 1 - slides
Understanding oracle rac internals part 1 - slides
 
Apache Solr Workshop
Apache Solr WorkshopApache Solr Workshop
Apache Solr Workshop
 
Oracle 表格介紹
Oracle 表格介紹Oracle 表格介紹
Oracle 表格介紹
 
Scaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ssScaling paypal workloads with oracle rac ss
Scaling paypal workloads with oracle rac ss
 
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
Oracle Real Application Clusters 19c- Best Practices and Internals- EMEA Tour...
 
Christo kutrovsky oracle, memory & linux
Christo kutrovsky   oracle, memory & linuxChristo kutrovsky   oracle, memory & linux
Christo kutrovsky oracle, memory & linux
 
SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
 
OOUG: Oracle transaction locking
OOUG: Oracle transaction lockingOOUG: Oracle transaction locking
OOUG: Oracle transaction locking
 
JSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in DatabaseJSON and PL/SQL: A Match Made in Database
JSON and PL/SQL: A Match Made in Database
 
Understanding oracle rac internals part 2 - slides
Understanding oracle rac internals   part 2 - slidesUnderstanding oracle rac internals   part 2 - slides
Understanding oracle rac internals part 2 - slides
 
Oracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic FunctionsOracle Advanced SQL and Analytic Functions
Oracle Advanced SQL and Analytic Functions
 
Oracle Database Management - Backup/Recovery
Oracle Database Management - Backup/RecoveryOracle Database Management - Backup/Recovery
Oracle Database Management - Backup/Recovery
 
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
Survey of some free Tools to enhance your SQL Tuning and Performance Diagnost...
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 

Similar to How to Find Patterns in Your Data with SQL

What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
Edureka!
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for Graphs
Jean Ihm
 
20190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev220190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev2
Ivan Ma
 
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech TalksOracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Amazon Web Services
 
2018 JCP Year End Summary
2018 JCP Year End Summary2018 JCP Year End Summary
2018 JCP Year End Summary
Heather VanCura
 
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Amazon Web Services
 
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
Amazon Web Services
 
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
OSS On Azure
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
Edureka!
 
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Amazon Web Services
 
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
Amazon Web Services
 
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech TalksData Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
Amazon Web Services
 
Migrating database to cloud
Migrating database to cloudMigrating database to cloud
Migrating database to cloud
Amazon Web Services
 
SageMaker Algorithms Infinitely Scalable Machine Learning
SageMaker Algorithms Infinitely Scalable Machine LearningSageMaker Algorithms Infinitely Scalable Machine Learning
SageMaker Algorithms Infinitely Scalable Machine Learning
Amazon Web Services
 
Amazon SageMaker Algorithms: Machine Learning Week San Francisco
Amazon SageMaker Algorithms: Machine Learning Week San FranciscoAmazon SageMaker Algorithms: Machine Learning Week San Francisco
Amazon SageMaker Algorithms: Machine Learning Week San Francisco
Amazon Web Services
 
#dbhouseparty - Real World Problem Solving with SQL
#dbhouseparty - Real World Problem Solving with SQL#dbhouseparty - Real World Problem Solving with SQL
#dbhouseparty - Real World Problem Solving with SQL
Tammy Bednar
 
2019 JCP Program Year End Summary
2019 JCP Program Year End Summary2019 JCP Program Year End Summary
2019 JCP Program Year End Summary
Heather VanCura
 
Top 10 SQL Performance tips & tricks for Java Developers
Top 10 SQL Performance tips & tricks for Java DevelopersTop 10 SQL Performance tips & tricks for Java Developers
Top 10 SQL Performance tips & tricks for Java Developers
gvenzl
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
Connor McDonald
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
Connor McDonald
 

Similar to How to Find Patterns in Your Data with SQL (20)

What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
What Is SAS | SAS Tutorial For Beginners | SAS Training | SAS Programming | E...
 
PGQL: A Language for Graphs
PGQL: A Language for GraphsPGQL: A Language for Graphs
PGQL: A Language for Graphs
 
20190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev220190615 hkos-mysql-troubleshootingandperformancev2
20190615 hkos-mysql-troubleshootingandperformancev2
 
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech TalksOracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
Oracle to Amazon Aurora Migration, Step by Step - AWS Online Tech Talks
 
2018 JCP Year End Summary
2018 JCP Year End Summary2018 JCP Year End Summary
2018 JCP Year End Summary
 
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
Build Deep Learning Applications Using Apache MXNet, Featuring Workday (AIM40...
 
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
FINRA's Managed Data Lake: Next-Gen Analytics in the Cloud - ENT328 - re:Inve...
 
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
Azure HDlnsight에서 R 및 Spark를 이용하여 확장 가능한 머신러닝
 
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
ReactJS Tutorial For Beginners | ReactJS Redux Training For Beginners | React...
 
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
Build Deep Learning Applications Using Apache MXNet - Featuring Chick-fil-A (...
 
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
Data preparation and transformation - Spin your straw into gold - Tel Aviv Su...
 
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech TalksData Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
Data Warehousing and Data Lake Analytics, Together - AWS Online Tech Talks
 
Migrating database to cloud
Migrating database to cloudMigrating database to cloud
Migrating database to cloud
 
SageMaker Algorithms Infinitely Scalable Machine Learning
SageMaker Algorithms Infinitely Scalable Machine LearningSageMaker Algorithms Infinitely Scalable Machine Learning
SageMaker Algorithms Infinitely Scalable Machine Learning
 
Amazon SageMaker Algorithms: Machine Learning Week San Francisco
Amazon SageMaker Algorithms: Machine Learning Week San FranciscoAmazon SageMaker Algorithms: Machine Learning Week San Francisco
Amazon SageMaker Algorithms: Machine Learning Week San Francisco
 
#dbhouseparty - Real World Problem Solving with SQL
#dbhouseparty - Real World Problem Solving with SQL#dbhouseparty - Real World Problem Solving with SQL
#dbhouseparty - Real World Problem Solving with SQL
 
2019 JCP Program Year End Summary
2019 JCP Program Year End Summary2019 JCP Program Year End Summary
2019 JCP Program Year End Summary
 
Top 10 SQL Performance tips & tricks for Java Developers
Top 10 SQL Performance tips & tricks for Java DevelopersTop 10 SQL Performance tips & tricks for Java Developers
Top 10 SQL Performance tips & tricks for Java Developers
 
Melbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without riskMelbourne Groundbreakers Tour - Upgrading without risk
Melbourne Groundbreakers Tour - Upgrading without risk
 
Sangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12cSangam 18 - The New Optimizer in Oracle 12c
Sangam 18 - The New Optimizer in Oracle 12c
 

More from Chris Saxon

Game of Fraud Detection with SQL and Machine Learning
Game of Fraud Detection with SQL and Machine LearningGame of Fraud Detection with SQL and Machine Learning
Game of Fraud Detection with SQL and Machine Learning
Chris Saxon
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
Chris Saxon
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
Chris Saxon
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Chris Saxon
 
Why Isn't My Query Using an Index? An Introduction to SQL Performance
Why Isn't My Query Using an Index? An Introduction to SQL PerformanceWhy Isn't My Query Using an Index? An Introduction to SQL Performance
Why Isn't My Query Using an Index? An Introduction to SQL Performance
Chris Saxon
 
12 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 212 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 2
Chris Saxon
 
How to Hack Your App Using SQL Injection
How to Hack Your App Using SQL InjectionHow to Hack Your App Using SQL Injection
How to Hack Your App Using SQL Injection
Chris Saxon
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c
Chris Saxon
 

More from Chris Saxon (8)

Game of Fraud Detection with SQL and Machine Learning
Game of Fraud Detection with SQL and Machine LearningGame of Fraud Detection with SQL and Machine Learning
Game of Fraud Detection with SQL and Machine Learning
 
Agile Database Development with JSON
Agile Database Development with JSONAgile Database Development with JSON
Agile Database Development with JSON
 
Polymorphic Table Functions in SQL
Polymorphic Table Functions in SQLPolymorphic Table Functions in SQL
Polymorphic Table Functions in SQL
 
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL ChangesUsing Edition-Based Redefinition for Zero Downtime PL/SQL Changes
Using Edition-Based Redefinition for Zero Downtime PL/SQL Changes
 
Why Isn't My Query Using an Index? An Introduction to SQL Performance
Why Isn't My Query Using an Index? An Introduction to SQL PerformanceWhy Isn't My Query Using an Index? An Introduction to SQL Performance
Why Isn't My Query Using an Index? An Introduction to SQL Performance
 
12 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 212 Things Developers Will Love About Oracle Database 12c Release 2
12 Things Developers Will Love About Oracle Database 12c Release 2
 
How to Hack Your App Using SQL Injection
How to Hack Your App Using SQL InjectionHow to Hack Your App Using SQL Injection
How to Hack Your App Using SQL Injection
 
18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c18(ish) Things You'll Love About Oracle Database 18c
18(ish) Things You'll Love About Oracle Database 18c
 

Recently uploaded

在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
ihavuls
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Fernanda Palhano
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
Bill641377
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
Walaa Eldin Moustafa
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
AlessioFois2
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
manishkhaire30
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
javier ramirez
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
SaffaIbrahim1
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
Sachin Paul
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
Lars Albertsson
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
Timothy Spann
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
soxrziqu
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
xclpvhuk
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 

Recently uploaded (20)

在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdfUdemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
Udemy_2024_Global_Learning_Skills_Trends_Report (1).pdf
 
Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...Population Growth in Bataan: The effects of population growth around rural pl...
Population Growth in Bataan: The effects of population growth around rural pl...
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data LakeViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
ViewShift: Hassle-free Dynamic Policy Enforcement for Every Data Lake
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 
A presentation that explain the Power BI Licensing
A presentation that explain the Power BI LicensingA presentation that explain the Power BI Licensing
A presentation that explain the Power BI Licensing
 
Learn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queriesLearn SQL from basic queries to Advance queries
Learn SQL from basic queries to Advance queries
 
The Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series DatabaseThe Building Blocks of QuestDB, a Time Series Database
The Building Blocks of QuestDB, a Time Series Database
 
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docxDATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
DATA COMMS-NETWORKS YR2 lecture 08 NAT & CLOUD.docx
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......Palo Alto Cortex XDR presentation .......
Palo Alto Cortex XDR presentation .......
 
End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024End-to-end pipeline agility - Berlin Buzzwords 2024
End-to-end pipeline agility - Berlin Buzzwords 2024
 
DSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelinesDSSML24_tspann_CodelessGenerativeAIPipelines
DSSML24_tspann_CodelessGenerativeAIPipelines
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
University of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma TranscriptUniversity of New South Wales degree offer diploma Transcript
University of New South Wales degree offer diploma Transcript
 
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
一比一原版(Unimelb毕业证书)墨尔本大学毕业证如何办理
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 

How to Find Patterns in Your Data with SQL

  • 1. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How to Find Patterns in Your Data with SQL Chris Saxon, @ChrisRSaxon & @SQLDaily blogs.oracle.com/sql youtube.com/c/TheMagicofSQL asktom.oracle.com
  • 2. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Safe Harbor Statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • 3. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | This presentation contains <regular expressions>!
  • 4. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | blogs.oracle.com/sql www.youtube.com/c/TheMagicOfSQL @ChrisRSaxon I thought this was about SQL! Ryan McGuire / Gratisography
  • 5. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
  • 6. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | * => zero or more matches + => one or more matches {n,m} => N through M matches (either optional)
  • 7. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Am I Improving? Can Beat My PB? Am I Training Regularly?
  • 8. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Am I running every day?
  • 9. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1
  • 10. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1 #1 #3 #2 #4
  • 11. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How I know if rows are consecutive?
  • 12. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current value = previous value + 1
  • 13. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | lag ( run_date ) over ( order by run_date ) Get the previous row's date
  • 14. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE RN TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 1 420 1 02 Jan 2018 2 2,400 5 03 Jan 2018 3 4,932 10 06 Jan 2018 4 2,350 5 07 Jan 2018 5 410 1 10 Jan 2018 6 400 1 13 Jan 2018 7 2,300 5 14 Jan 2018 8 425 1 15 Jan 2018 9 422 1 consecutive => constant gap
  • 15. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE RN TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 1 420 1 02 Jan 2018 2 2,400 5 03 Jan 2018 3 4,932 10 06 Jan 2018 4 2,350 5 07 Jan 2018 5 410 1 10 Jan 2018 6 400 1 13 Jan 2018 7 2,300 5 14 Jan 2018 8 425 1 15 Jan 2018 9 422 1 - - - - - - - - -
  • 16. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE RN RUN_DATE - RN TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 1 31 Dec 2017 420 1 02 Jan 2018 2 31 Dec 2017 2,400 5 03 Jan 2018 3 31 Dec 2017 4,932 10 06 Jan 2018 4 02 Jan 2018 2,350 5 07 Jan 2018 5 02 Jan 2018 410 1 10 Jan 2018 6 04 Jan 2018 400 1 13 Jan 2018 7 06 Jan 2018 2,300 5 14 Jan 2018 8 06 Jan 2018 425 1 15 Jan 2018 9 06 Jan 2018 422 1 - - - - - - - - -
  • 17. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE RN RUN_DATE - RN TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 1 31 Dec 2017 420 1 02 Jan 2018 2 31 Dec 2017 2,400 5 03 Jan 2018 3 31 Dec 2017 4,932 10 06 Jan 2018 4 02 Jan 2018 2,350 5 07 Jan 2018 5 02 Jan 2018 410 1 10 Jan 2018 6 04 Jan 2018 400 1 13 Jan 2018 7 06 Jan 2018 2,300 5 14 Jan 2018 8 06 Jan 2018 425 1 15 Jan 2018 9 06 Jan 2018 422 1 - - - - - - - - -
  • 18. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tabibitosan Method
  • 19. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | row_number () over ( order by run_date )
  • 20. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | run_date - row_number () over ( order by run_date ) grp
  • 21. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with grps as ( select run_date , run_date - row_number () over ( order by run_date ) grp from running_log r ) select min ( run_date ), count (*) from grps group by grp
  • 22. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12c Pattern Matching
  • 23. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1 this = prev + 1
  • 24. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1 this = prev + 1 this = prev + 3
  • 25. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1 this = prev + 1 this = prev + 3 this ≠ prev + 1
  • 26. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | define consecutive as run_date = prev ( run_date ) + 1
  • 27. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1
  • 28. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1 "Always true" > 0 matches Any row <>
  • 29. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE VARIABLE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 STRT 420 1 02 Jan 2018 CONSECUTIVE 2,400 5 03 Jan 2018 CONSECUTIVE 4,932 10 06 Jan 2018 STRT 2,350 5 07 Jan 2018 CONSECUTIVE 410 1 10 Jan 2018 STRT 400 1 13 Jan 2018 STRT 2,300 5 14 Jan 2018 CONSECUTIVE 425 1 15 Jan 2018 CONSECUTIVE 422 1
  • 30. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1 Which row is prev?!
  • 31. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | order by run_date pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1
  • 32. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1 ); How many consecutive rows? From first row in group
  • 33. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | START_DATE DAYS 01 Jan 2018 3 06 Jan 2018 2 10 Jan 2018 1 13 Jan 2018 3
  • 34. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | So which is better? Pixabay pattern matching
  • 35. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Performance ~ similar Availability MR 12c vs 8i* Readability personal pref Match_recognize vs. Tabibitosan
  • 36. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Am I running >= 3 times/week? Pixabay
  • 37. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How I know if runs are in the same week?
  • 38. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | last Monday = prev last Monday
  • 39. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | trunc ( run_date , 'iw' ) Return the start of the ISO week… …Monday!
  • 40. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TRUNC(RUN_DATE, 'IW') TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 Jan 2018 420 1 02 Jan 2018 01 Jan 2018 2,400 5 03 Jan 2018 01 Jan 2018 4,932 10 06 Jan 2018 01 Jan 2018 2,350 5 07 Jan 2018 01 Jan 2018 410 1 10 Jan 2018 08 Jan 2018 400 1 13 Jan 2018 08 Jan 2018 2,300 5 14 Jan 2018 08 Jan 2018 425 1 15 Jan 2018 15 Jan 2018 422 1
  • 41. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select trunc ( run_date , 'iw' ), count(*) from running_log group by trunc ( run_date , 'iw' )
  • 42. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select trunc ( run_date , 'iw' ), count(*) from running_log group by trunc ( run_date , 'iw' ) having count (*) >= 3
  • 43. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12c Pattern Matching
  • 44. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | define same_week as trunc ( run_date, 'iw' ) = prev ( trunc ( run_date, 'iw' ) )
  • 45. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( strt same_week* ) define same_week as trunc ( run_date, 'iw' ) = prev ( trunc ( run_date, 'iw' ) ) );
  • 46. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( strt same_week {2, } ) define same_week as trunc ( run_date, 'iw' ) = prev ( trunc ( run_date, 'iw' ) ) ); Two or more matches
  • 47. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( strt same_week {2, } ) define same_week as trunc ( run_date, 'iw' ) = prev ( trunc ( run_date, 'iw' ) ) );
  • 48. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( strt consecutive* ) define consecutive as run_date = prev ( run_date ) + 1 );
  • 49. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How I can I find consecutive weeks with >= 3 runs?
  • 50. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Find weeks >= 3 runs then check these are consecutive!
  • 51. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with min_three_runs as ( select * from running_log match_recognize ( order by run_date measures first ( trunc ( run_date, 'iw' ) ) as week_start, count(*) as days pattern ( strt same_week {2, } ) define same_week as trunc ( run_date, 'iw' ) = prev ( trunc ( run_date, 'iw' ) ) )
  • 52. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How I can I find consecutive weeks?
  • 53. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current Monday = prev Monday + 7
  • 54. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tabibitosan Method
  • 55. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | WEEK_START RN WEEK_START – RN RUNS 01 Jan 2018 1 31 Dec 2017 5 08 Jan 2018 2 06 Jan 2018 3 15 Jan 2018 3 12 Jan 2018 4 05 Feb 2018 4 01 Feb 2018 3 12 Feb 2018 5 07 Feb 2018 3 05 Mar 2018 6 28 Feb 2018 3 12 Mar 2018 7 07 Mar 2018 4
  • 56. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Tabibitosan Method
  • 57. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | WEEK_START RN * 7 RUNS 01 Jan 2018 7 5 08 Jan 2018 14 3 15 Jan 2018 21 4 05 Feb 2018 28 3 12 Feb 2018 35 3 05 Mar 2018 42 3 12 Mar 2018 49 4
  • 58. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | WEEK_START RN * 7 WEEK_START – ( RN * 7 ) RUNS 01 Jan 2018 7 25 Dec 2017 5 08 Jan 2018 14 25 Dec 2017 3 15 Jan 2018 21 25 Dec 2017 4 05 Feb 2018 28 08 Jan 2018 3 12 Feb 2018 35 08 Jan 2018 3 05 Mar 2018 42 22 Jan 2018 3 12 Mar 2018 49 22 Jan 2018 4
  • 59. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select run_date - ( 7 * row_number() over ( order by run_date ) ) grp from min_three_runs
  • 60. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by week_start measures first ( week_start ) as start_date, count (*) as weeks pattern ( strt consecutive_weeks* ) define consecutive_weeks as week_start = prev ( week_start ) + 7 );
  • 61. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
  • 62. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Pixabay Am I running >= 3 times in 7 days?
  • 63. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current day < first day + 7
  • 64. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1
  • 65. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1 #1 #2
  • 66. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 – 07 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 08 – 14 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 15 – 21 Jan 2018 422 1
  • 67. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 – 07 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 08 – 14 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 15 – 21 Jan 2018 422 1
  • 68. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 – 07 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 2,350 5 07 Jan 2018 410 1 10 Jan 2018 10 – 17 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1
  • 69. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select r.*, min ( run_date ) over ( order by run_date ) mn_date from running_log r
  • 70. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 Jan 2018 420 1 02 Jan 2018 01 Jan 2018 2,400 5 03 Jan 2018 01 Jan 2018 4,932 10 06 Jan 2018 01 Jan 2018 2,350 5 07 Jan 2018 01 Jan 2018 410 1 10 Jan 2018 01 Jan 2018 400 1 13 Jan 2018 01 Jan 2018 2,300 5 14 Jan 2018 01 Jan 2018 425 1 15 Jan 2018 01 Jan 2018 422 1
  • 71. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Windowing clause to the rescue…
  • 72. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select r.*, min ( run_date ) over ( order by run_date range between 7 preceding and current row ) mn_date from running_log r Consider rows with values in the previous 7 days
  • 73. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 Jan 2018 420 1 02 Jan 2018 01 Jan 2018 2,400 5 03 Jan 2018 01 Jan 2018 4,932 10 06 Jan 2018 01 Jan 2018 2,350 5 07 Jan 2018 01 Jan 2018 410 1 10 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1
  • 74. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 Jan 2018 420 1 02 Jan 2018 01 Jan 2018 2,400 5 03 Jan 2018 01 Jan 2018 4,932 10 06 Jan 2018 01 Jan 2018 2,350 5 07 Jan 2018 01 Jan 2018 410 1 10 Jan 2018 03 Jan 2018 400 1 13 Jan 2018 2,300 5 14 Jan 2018 425 1 15 Jan 2018 422 1
  • 75. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE MN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 01 Jan 2018 420 1 02 Jan 2018 01 Jan 2018 2,400 5 03 Jan 2018 01 Jan 2018 4,932 10 06 Jan 2018 01 Jan 2018 2,350 5 07 Jan 2018 01 Jan 2018 410 1 10 Jan 2018 03 Jan 2018 400 1 13 Jan 2018 06 Jan 2018 2,300 5 14 Jan 2018 07 Jan 2018 425 1 15 Jan 2018 10 Jan 2018 422 1
  • 76. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Windowing clause to the rescue!
  • 77. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 11.2 Recursive With
  • 78. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with rws as ( select r.*, row_number() over ( order by run_date ) rn from running_log r )
  • 79. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with rws as ( select r.*, row_number() over ( order by run_date ) rn from running_log r ), within_7 ( run_date, time_in_s, distance_in_miles, rn, grp_start ) as ( select run_date, time_in_s, distance_in_miles, rn, run_date grp_start from rws where rn = 1
  • 80. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with rws as ( select r.*, row_number() over ( order by run_date ) rn from running_log r ), within_7 ( run_date, time_in_s, distance_in_miles, rn, grp_start ) as ( select run_date, time_in_s, distance_in_miles, rn, run_date grp_start from rws where rn = 1 union all select r.run_date, r.time_in_s, r.distance_in_miles, r.rn, from within_7 w join rws r on w.rn + 1 = r.rn )
  • 81. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with rws as ( select r.*, row_number() over ( order by run_date ) rn from running_log r ), within_7 ( run_date, time_in_s, distance_in_miles, rn, grp_start ) as ( select run_date, time_in_s, distance_in_miles, rn, run_date grp_start from rws where rn = 1 union all select r.run_date, r.time_in_s, r.distance_in_miles, r.rn, case when r.run_date < w.grp_start + 7 then grp_start else r.run_date end grp_start from within_7 w join rws r on w.rn + 1 = r.rn )
  • 82. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | with rws as ( select r.*, row_number() over ( order by run_date ) rn from running_log r ), within_7 ( run_date, time_in_s, distance_in_miles, rn, grp_start ) as ( select run_date, time_in_s, distance_in_miles, rn, run_date grp_start from rws where rn = 1 union all select r.run_date, r.time_in_s, r.distance_in_miles, r.rn, case when r.run_date < w.grp_start + 7 then grp_start else r.run_date end grp_start from within_7 w join rws r on w.rn + 1 = r.rn ) select grp, w.* from within_7 w
  • 83. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 10g Model
  • 84. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select * from running_log model dimension by ( row_number() over ( order by run_date ) rn ) measures ( run_date, 1 grp, run_date grp_start ) rules ( grp_start[1] = run_date[cv()], grp_start[any] = case when run_date[cv()] < grp_start[cv()-1] + 7 then grp_start[cv() - 1] else run_date[cv()] end , grp[any] = case when run_date[cv()] < grp_start[cv()-1] + 7 then grp[cv() - 1] else nvl(grp[cv() - 1] + 1, 1) end );
  • 85. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12c Pattern Matching
  • 86. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current day < first day + 7
  • 87. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | define within7 as run_date < first ( run_date ) + 7
  • 88. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( within7+ ) define within7 as run_date < first ( run_date ) + 7 > 1 matches
  • 89. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as days pattern ( within7+ ) define within7 as run_date < first ( run_date ) + 7 );
  • 90. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Am I getting faster? stocksnap.io
  • 91. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current time < prev time
  • 92. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Analytic Functions
  • 93. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | lag ( time_in_s ) over ( order by run_date )
  • 94. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | select r.*, case when time_in_s < lag ( time_in_s ) over ( order by run_date ) then 'FASTER' else 'SLOWER' end faster from running_log r
  • 95. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | 12c Pattern Matching
  • 96. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | current time < prev time
  • 97. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | define faster as time_in_s < prev ( time_in_s )
  • 98. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( slower faster* ) define faster as time_in_s < prev ( time_in_s )
  • 99. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures classifier () as faster pattern ( slower faster* ) define faster as time_in_s < prev ( time_in_s ) );
  • 100. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | FASTER SLOWER SLOWER FASTER FASTER
  • 101. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures classifier () as faster one row per match pattern ( slower faster* ) define faster as time_in_s < prev ( time_in_s ) );
  • 102. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures classifier () as faster all rows per match pattern ( slower faster* ) define faster as time_in_s < prev ( time_in_s ) );
  • 103. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 SLOWER 420 1 02 Jan 2018 SLOWER 2,400 5 03 Jan 2018 SLOWER 4,932 10 06 Jan 2018 FASTER 2,350 5 07 Jan 2018 FASTER 410 1 10 Jan 2018 FASTER 400 1 13 Jan 2018 SLOWER 2,300 5 14 Jan 2018 FASTER 425 1 15 Jan 2018 FASTER 422 1
  • 104. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 SLOWER 420 1 02 Jan 2018 SLOWER 2,400 5 03 Jan 2018 SLOWER 4,932 10 06 Jan 2018 FASTER 2,350 5 07 Jan 2018 FASTER 410 1 10 Jan 2018 FASTER 400 1 13 Jan 2018 SLOWER 2,300 5 14 Jan 2018 FASTER 425 1 15 Jan 2018 FASTER 422 1 SLOWER!
  • 105. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 07 Jan 2018 410 1 10 Jan 2018 400 1 14 Jan 2018 425 1 15 Jan 2018 422 1 02 Jan 2018 2,400 5 06 Jan 2018 2,350 5 13 Jan 2018 2,300 5 03 Jan 2018 4,932 10
  • 106. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( partition by distance_in_miles order by run_date measures classifier () as faster all rows per match pattern ( slower faster* ) define faster as time_in_s < prev ( time_in_s ) );
  • 107. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE FASTER TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 SLOWER 420 1 07 Jan 2018 FASTER 410 1 10 Jan 2018 FASTER 400 1 14 Jan 2018 SLOWER 425 1 15 Jan 2018 FASTER 422 1 02 Jan 2018 SLOWER 2,400 5 06 Jan 2018 FASTER 2,350 5 13 Jan 2018 FASTER 2,300 5 03 Jan 2018 SLOWER 4,932 10
  • 108. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Can I run 10k in < 50 minutes?
  • 109. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Sum the total distance for runs with a total time < 50 minutes
  • 110. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | cumulative time <= 3,000 seconds
  • 111. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( fifty_minutes+ ) define fifty_minutes as sum ( time_in_s ) <= 3000 Returns the running total
  • 112. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as strt , sum ( time_in_s ) as total_time, sum ( distance_in_miles ) as dist pattern ( fifty_minutes+ ) define fifty_minutes as sum ( time_in_s ) <= 3000 );
  • 113. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | STRT TOTAL_TIME DIST 01 Jan 2018 2,820 6 06 Jan 2018 2,760 6 10 Jan 2018 2,700 6 14 Jan 2018 847 2 Where's my 10 mile run?
  • 114. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | any runs cumulative time < 3,000 and one run cumulative time >= 3,000
  • 115. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( )
  • 116. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( under_fifty* over_fifty )
  • 117. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( under_fifty* over_fifty ) define under_fifty as sum ( time_in_s ) < 3000, over_fifty as sum ( time_in_s ) >= 3000 ); Includes under_fifty values
  • 118. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as strt , sum ( time_in_s ) as total_time, sum ( distance_in_miles ) as dist pattern ( under_fifty* over_fifty ) define under_fifty as sum ( time_in_s ) < 3000, over_fifty as sum ( time_in_s ) >= 3000 );
  • 119. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | STRT TOTAL_TIME DIST 01 Jan 2018 7,752 16 06 Jan 2018 3,160 7 13 Jan 2018 3,147 7 Hmmm….
  • 120. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as strt , sum ( time_in_s ) as total_time, sum ( distance_in_miles ) as dist after match skip past last row pattern ( under_fifty* over_fifty ) define under_fifty as sum ( time_in_s ) < 3000, over_fifty as sum ( time_in_s ) >= 3000 );
  • 121. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as strt , sum ( time_in_s ) as total_time, sum ( distance_in_miles ) as dist after match skip to next row pattern ( under_fifty* over_fifty ) define under_fifty as sum ( time_in_s ) < 3000, over_fifty as sum ( time_in_s ) >= 3000 );
  • 122. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | STRT TOTAL_TIME DIST 01 Jan 2018 7,752 16 02 Jan 2018 7,332 15 03 Jan 2018 4,932 10 06 Jan 2018 3,160 7 07 Jan 2018 3,110 7 10 Jan 2018 3,125 7 13 Jan 2018 3,147 7
  • 123. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Pixabay
  • 124. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How often did I run 5 miles Followed by 2+ 1 mile runs Within 7 days?
  • 125. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( five_mile one_mile {2,} ) define
  • 126. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( five_mile one_mile {2,} ) define five_mile as distance_in_miles = 5,
  • 127. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( five_mile one_mile {2,} ) define five_mile as distance_in_miles = 5, one_mile as distance_in_miles = 1
  • 128. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | pattern ( five_mile one_mile {2,} ) define five_mile as distance_in_miles = 5, one_mile as distance_in_miles = 1 and run_date < first ( run_date ) + 7
  • 129. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures first ( run_date ) as start_date, count (*) as total_runs pattern ( five_mile one_mile {2,} ) define five_mile as distance_in_miles = 5, one_mile as distance_in_miles = 1 and run_date < first ( run_date ) + 7 );
  • 130. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | STRT TOTAL_RUNS 06 Jan 2018 3 13 Jan 2018 3
  • 131. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Why would I want to do that?!
  • 132. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Pixabay
  • 133. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | How do I debug it? Gratisography
  • 134. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | (Regular) [exprsion]+ are easy to missteak
  • 135. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | regex101.comregex101.com
  • 136. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | classifier => Which variable matched?
  • 137. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | classifier => Which variable matched? match_number => Which group is this?
  • 138. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | classifier => Which variable matched? match_number => Which group is this? all rows per match
  • 139. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | classifier => Which variable matched? match_number => Which group is this? all rows per match with unmatched rows => Show me everything!
  • 140. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | match_recognize ( order by run_date measures classifier () as var, match_number () as grp all rows per match with unmatched rows pattern ( five_mile one_mile {2,} ) define five_mile as distance_in_miles = 5, one_mile as distance_in_miles = 1 and run_date < first ( run_date ) + 7 );
  • 141. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | RUN_DATE VAR GRP TIME_IN_S DISTANCE_IN_MILES 01 Jan 2018 420 1 02 Jan 2018 2,400 5 03 Jan 2018 4,932 10 06 Jan 2018 FIVE_MILE 1 2,350 5 07 Jan 2018 ONE_MILE 1 410 1 10 Jan 2018 ONE_MILE 1 400 1 13 Jan 2018 FIVE_MILE 2 2,300 5 14 Jan 2018 ONE_MILE 2 425 1 15 Jan 2018 ONE_MILE 2 422 1
  • 142. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Want more? Pixabay
  • 143. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. |
  • 144. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | iTunes & PDF FREE! SQL for Data Warehousing and Analytics https://oracle-big-data.blogspot.co.uk Keith Laker Analytic SQL PM
  • 145. Copyright © 2017, Oracle and/or its affiliates. All rights reserved. | Gratisography #MakeDataGreatAgain oracle-big-data.blogspot.co.uk