tailieunhanh - Joe Celko s SQL for Smarties - Advanced SQL Programming P75

Joe Celko s SQL for Smarties - Advanced SQL Programming P75. In the SQL database community, Joe Celko is a well-known columnist and purveyor of valuable insights. In Joe Celko's SQL for Smarties: Advanced SQL Programming, he picks up where basic SQL training and experience leaves many database professionals and offers tips, techniques, and explanations that help readers extend their capabilities to top-tier SQL programming. Although Celko denies that the book is about database theory, he nevertheless alludes to theory often to buttress his practical points. This title is not for novices, as the author points out. Instead, its intended. | 712 CHAPTER 31 OLAP IN SQL defined by an ordering clause if one is specified starting with one for the first row and continuing sequentially to the last row in the window. If an ordering clause order by isn t specified in the window the row numbers are assigned to the rows in arbitrary order as returned by the subselect. GROUPING Operators OLAP functions add the ROLLUP and CUBE extensions to the GROUP BY clause. rollup and cube are often referred to as supergroups. They can be written in older Standard SQL using GROUP BY and UNION operators. GROUP BY GROUPING SET The GROUPING SET column list is shorthand in SQL-99 for a series of UNIONed queries that are common in reports. For example to find the total SELECT dept_name CAST NULL AS CHAR 10 AS job_title COUNT FROM Personnel GROUP BY dept_name UNION ALL SELECT CAST NULL AS CHAR 8 AS dept_name job_title COUNT FROM Personnel GROUP BY job_title The above can be rewritten like this. SELECT dept_name job_title COUNT FROM Personnel GROUP BY GROUPING SET dept_name job_title There is a problem with all of the OLAP grouping functions. They will generate NULLs for each dimension at the subtotal levels. How do you tell the difference between a real NULL and a generated NULL This is a job for the GROUPING function which returns zeros for NULLs in the original data and ones for generated NULLs that indicate a subtotal. SELECT CASE GROUPING dept_name WHEN 1 THEN department total ELSE dept_name END AS dept_name OLAP Functionality 713 CASE GROUPING job_title WHEN 1 THEN job total ELSE job_title_name END AS job_title FROM Personnel GROUP BY GROUPING SETS dept_name job_title The grouping set concept can be used to define other OLAP groupings. ROLLUP A ROLLUP group an extension to the GROUP BY clause in SQL-99 produces a result set that contains subtotal rows in addition to the regular grouped rows. Subtotal rows are superaggregate rows that contain further aggregates whose values are derived by applying the same column .

crossorigin="anonymous">
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.