TAILIEUCHUNG - Joe Celko s SQL for Smarties - Advanced SQL Programming P47

Joe Celko s SQL for Smarties - Advanced SQL Programming P47. 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 audience. | 432 CHAPTER 20 GROUPING OPERATIONS group can have only one count one minimum one maximum one average and so forth for any expression. The nature of descriptive statistics is that they reduce a group characteristic to a scalar value. Grouped VIEWs for Multiple Aggregation Levels Business reports are usually based on a hierarchy of nested levels of aggregation. This type of report is so common that there are tools that perform only this sort of task. For example sales are grouped under the salesmen who made them then salesmen s departments are grouped into districts districts are grouped into regions and so on until we have summary information at the company level. Each level is a partition of the level above it. The summary information can be constructed from the level immediately beneath it in the hierarchy. Look at Chapter 28 on the Nested Sets model for hierarchies. Frankly using a report writer will be faster and more powerful than writing SQL code to do the job. One trick is to use views with group by clauses to build the reporting levels. Using a Sales report example the following UNiONed query will get a report for each level from the lowest most detailed level salesman through districts and regions to the highest level the company . SELECT region district salesman SUM sales_sales_amt FROM Sales GROUP BY region district salesman UNION SELECT region district SALESMEN SUM sales_amt FROM Sales GROUP BY region district UNION SELECT region OFFICE SALESMEN SUM sales_amt FROM Sales GROUP BY region UNION SELECT REGION OFFICE SALESMEN SUM sales_amt FROM Sales The constant strings inside the curly brackets will sort below any alphabetic strings in ASCII and thus will appear on the end of each grouping in the hierarchy. Now that I ve shown you this trick I need to point out its flaws. Multiple Aggregation Levels 433 Subquery Expressions for Multiple Aggregation Levels Standard SQL permits you to use a table subquery in a from clause and a scalar .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.