Đang chuẩn bị liên kết để tải về tài liệu:
Joe Celko s SQL for Smarties - Advanced SQL Programming P57

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Joe Celko s SQL for Smarties - Advanced SQL Programming P57. 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. | 532 CHAPTER 23 STATISTICS IN SQL CREATE TABLE Sales salesman CHAR 10 client_name CHAR 10 sales_amount DECIMAL 9 2 NOT NULL PRIMARY KEY salesman client_name The problem is to show each salesman his client the amount of that sale what percentage of his total sales volume that one sale represents and the cumulative percentage of his total sales we have reached at that point. We will sort the clients from the largest amount to the smallest. This problem is based on a salesman s report originally written for a small commercial printing company. The idea was to show the salesmen where their business was coming from and to persuade them to give up their smaller accounts defined as the lower 20 to new salesmen. The report lets the salesman run his finger down the page and see which customers represented the top 80 of his income. We can use derived tables to build layers of aggregation in the same query. SELECT SO.salesman S0.client_name S0.sales_amt SO.sales_amt 100 ST.salesman_total AS percent_of_total SUM S1.sales_amt S0.sales_amt 100 ST.salesman_total AS cum_percent FROM Sales AS S0 INNER JOIN Sales AS S1 ON S0.salesman S0.client_name Sl.salesman S1.client_name INNER JOIN SELECT S2.salesman SUM S1.sales_amt FROM Sales AS S2 GROUP BY S2.salesman AS ST salesman salesman_total ON S0.salesman ST.salesman GROUP BY S0.salesman S0.client_name S0.sales_amt However ifyour SQL allows subqueries in the SELECT clause but not in the FROM clause you can fake it with this query 23.6 Cumulative Statistics 533 SELECT S0.salesman S0.client_name S0.sales_amt S0.sales_amt 100.00 SELECT SUM S1.sales_amt FROM Sales AS S1 WHERE S0.salesman Sl.salesman AS percentage_of_total SELECT SUM S3.sales_amt FROM Sales AS S3 WHERE S0.salesman S3.salesman AND S3.sales_amt S0.sales_amt OR S3.sales_amt S0.sales_amt AND S3.client_name S0.client_name 100.00 SELECT SUM S2.sales_amt FROM Sales AS S2 WHERE S0.salesman S2.salesman AS cum_percent FROM Sales AS S0 This query will probably run like glue. 23.6.4 .

Đã 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.