About the Author |
|
xiii | |
Acknowledgments |
|
xv | |
Introduction |
|
xvii | |
Part I: Core SQL |
|
1 | (190) |
|
Chapter 1 Correlating Inline Views |
|
|
3 | (14) |
|
Brewery products and sales |
|
|
3 | (2) |
|
Scalar subqueries and multiple columns |
|
|
5 | (4) |
|
|
9 | (7) |
|
Outer joining correlated inline view |
|
|
12 | (4) |
|
|
16 | (1) |
|
Chapter 2 Pitfalls of Set Operations |
|
|
17 | (22) |
|
|
18 | (2) |
|
|
20 | (7) |
|
|
21 | (4) |
|
|
25 | (2) |
|
|
27 | (7) |
|
|
28 | (2) |
|
|
30 | (2) |
|
|
32 | (2) |
|
Minus vs. multiset except |
|
|
34 | (4) |
|
|
38 | (1) |
|
Chapter 3 Divide and Conquer with Subquery Factoring |
|
|
39 | (18) |
|
|
40 | (1) |
|
Best-selling years of the less strong beers |
|
|
40 | (4) |
|
Modularization using the with clause |
|
|
44 | (11) |
|
Multiple uses of the same subquery |
|
|
47 | (4) |
|
|
51 | (4) |
|
|
55 | (2) |
|
Chapter 4 Tree Calculations with Recursion |
|
|
57 | (16) |
|
Bottles in boxes on pallets |
|
|
57 | (3) |
|
Multiplying hierarchical quantities |
|
|
60 | (11) |
|
Recursive subquery factoring |
|
|
61 | (7) |
|
Dynamic SQL in PUSQL function |
|
|
68 | (3) |
|
|
71 | (2) |
|
Chapter 5 Functions Defined Within SQL |
|
|
73 | (14) |
|
Table with beer alcohol data |
|
|
73 | (2) |
|
Blood alcohol concentration |
|
|
75 | (2) |
|
|
77 | (3) |
|
Function in the with clause |
|
|
80 | (5) |
|
|
83 | (2) |
|
|
85 | (2) |
|
Chapter 6 Iterative Calculations with Multidimensional Data |
|
|
87 | (20) |
|
|
87 | (2) |
|
Live neighbor count with the model clause |
|
|
89 | (7) |
|
|
96 | (10) |
|
|
106 | (1) |
|
Chapter 7 Unpivoting Columns to Rows |
|
|
107 | (24) |
|
|
108 | (1) |
|
|
108 | (12) |
|
Do-it-yourself unpivoting |
|
|
111 | (2) |
|
More than one dimension and/or measure |
|
|
113 | (7) |
|
|
120 | (8) |
|
Dynamic mapping to dimension tables |
|
|
123 | (5) |
|
|
128 | (3) |
|
Chapter 8 Pivoting Rows to Columns |
|
|
131 | (14) |
|
|
132 | (2) |
|
Pivoting single measure and dimension |
|
|
134 | (5) |
|
Do-it-yourself manual pivoting |
|
|
138 | (1) |
|
|
139 | (5) |
|
Multiple dimensions as well |
|
|
141 | (3) |
|
|
144 | (1) |
|
Chapter 9 Splitting Delimited Text |
|
|
145 | (24) |
|
Customer favorites and reviews |
|
|
145 | (1) |
|
|
146 | (11) |
|
|
147 | (5) |
|
Built-in APEX table function |
|
|
152 | (1) |
|
Straight SQL with row generators |
|
|
153 | (2) |
|
Treating the string as a JSON array |
|
|
155 | (2) |
|
Delimited multiple values |
|
|
157 | (11) |
|
Custom ODCI table function |
|
|
157 | (5) |
|
Combining apex_string.split and substr |
|
|
162 | (1) |
|
Row generators and regexp_substr |
|
|
163 | (2) |
|
|
165 | (3) |
|
|
168 | (1) |
|
Chapter 10 Creating Delimited Text |
|
|
169 | (22) |
|
Delimited lists of products |
|
|
169 | (2) |
|
|
171 | (13) |
|
Aggregate function listagg |
|
|
172 | (1) |
|
Aggregate function collect |
|
|
173 | (4) |
|
Custom aggregate function stragg |
|
|
177 | (5) |
|
Aggregate function xmlagg |
|
|
182 | (2) |
|
When it doesn't fit in a VARCHAR2 |
|
|
184 | (6) |
|
Get just the first part of the result |
|
|
185 | (1) |
|
Try to make it fit with reduced data |
|
|
186 | (1) |
|
Use a CLOB instead of a VARCHAR2 |
|
|
187 | (3) |
|
|
190 | (1) |
Part II: Analytic Functions |
|
191 | (132) |
|
Chapter 11 Analytic Partitions, Ordering, and Windows |
|
|
193 | (22) |
|
|
194 | (1) |
|
|
195 | (8) |
|
|
197 | (2) |
|
|
199 | (4) |
|
Flexibility of the window clause |
|
|
203 | (3) |
|
|
206 | (2) |
|
The danger of the default window |
|
|
208 | (5) |
|
|
213 | (2) |
|
Chapter 12 Answering Top-N Questions |
|
|
215 | (22) |
|
|
215 | (7) |
|
Which kind of Top-3 do you mean? |
|
|
217 | (1) |
|
The sales data for the beer |
|
|
218 | (4) |
|
Traditional rownum method |
|
|
222 | (1) |
|
Analytic functions for ranking |
|
|
222 | (3) |
|
Fetch only the first rows |
|
|
225 | (6) |
|
|
226 | (3) |
|
What the row limiting clause cannot do |
|
|
229 | (2) |
|
Top-N in multiple partitions |
|
|
231 | (4) |
|
The lateral trick for the row limiting clause |
|
|
233 | (2) |
|
|
235 | (2) |
|
Chapter 13 Ordered Subsets with Rolling Sums |
|
|
237 | (30) |
|
|
238 | (2) |
|
|
240 | (24) |
|
Solving picking an order by FIFO |
|
|
240 | (6) |
|
Easy switch of picking principle |
|
|
246 | (2) |
|
Solving optimal picking route |
|
|
248 | (4) |
|
|
252 | (10) |
|
Finalizing the complete picking SQL |
|
|
262 | (2) |
|
|
264 | (3) |
|
Chapter 14 Analyzing Activity Logs with Lead |
|
|
267 | (20) |
|
|
268 | (3) |
|
Analyzing departures and arrivals |
|
|
271 | (4) |
|
Analyzing picking activity |
|
|
275 | (8) |
|
Complete picking cycle analysis |
|
|
280 | (3) |
|
Teaser: row pattern matching |
|
|
283 | (3) |
|
|
286 | (1) |
|
Chapter 15 Forecasting with Linear Regression |
|
|
287 | (20) |
|
|
288 | (17) |
|
|
289 | (3) |
|
Calculating the basis for regression |
|
|
292 | (6) |
|
|
298 | (3) |
|
|
301 | (4) |
|
|
305 | (2) |
|
Chapter 16 Rolling Sums to Forecast Reaching Minimums |
|
|
307 | (16) |
|
Inventory, budget, and order |
|
|
307 | (4) |
|
|
310 | (1) |
|
|
311 | (4) |
|
Restocking when minimum reached |
|
|
315 | (7) |
|
|
322 | (1) |
Part III: Row Pattern Matching |
|
323 | (130) |
|
Chapter 17 Up-and-Down Patterns |
|
|
325 | (26) |
|
|
325 | (2) |
|
Classifying downs and ups |
|
|
327 | (5) |
|
|
332 | (9) |
|
Revisiting if SAME is needed |
|
|
338 | (3) |
|
|
341 | (8) |
|
|
346 | (3) |
|
|
349 | (2) |
|
Chapter 18 Grouping Data Through Patterns |
|
|
351 | (20) |
|
Two sets of data to group |
|
|
351 | (1) |
|
Three grouping conditions |
|
|
352 | (17) |
|
|
353 | (11) |
|
Group until gap too large |
|
|
364 | (3) |
|
|
367 | (2) |
|
|
369 | (2) |
|
Chapter 19 Merging Date Ranges |
|
|
371 | (18) |
|
|
371 | (7) |
|
|
375 | (3) |
|
Merging overlapping ranges |
|
|
378 | (10) |
|
Attempts comparing to the previous row |
|
|
379 | (2) |
|
Better comparing to the maximum end date |
|
|
381 | (5) |
|
|
386 | (2) |
|
|
388 | (1) |
|
Chapter 20 Finding Abnormal Peaks |
|
|
389 | (22) |
|
|
389 | (2) |
|
|
391 | (6) |
|
Patterns in the raw counter data |
|
|
393 | (4) |
|
|
397 | (13) |
|
Patterns in daily visits data |
|
|
399 | (7) |
|
|
406 | (4) |
|
|
410 | (1) |
|
|
411 | (24) |
|
Inventory to be packed in boxes |
|
|
411 | (2) |
|
Bin fitting with unlimited number of bins of limited capacity |
|
|
413 | (13) |
|
Showing where box capacity is too small |
|
|
422 | (4) |
|
Bin fitting with limited number of bins of unlimited capacity |
|
|
426 | (7) |
|
|
433 | (2) |
|
Chapter 22 Counting Children in Trees |
|
|
435 | (18) |
|
Hierarchical tree of employees |
|
|
435 | (2) |
|
Counting subordinates of all levels |
|
|
437 | (14) |
|
Counting with row pattern matching |
|
|
439 | (3) |
|
The details of each match |
|
|
442 | (6) |
|
|
448 | (3) |
|
|
451 | (2) |
Index |
|
453 | |