TAILIEUCHUNG - SQL VISUAL QUICKSTART GUIDE- P22

SQL VISUAL QUICKSTART GUIDE- P22:SQL (pronounced es-kyoo-el) is the standard programming language for creating, updating, and retrieving information that is stored in databases. With SQL, you can turn your ordinary questions (“Where do our customers live?”) into statements that your database system can understand (SELECT DISTINCT city, state FROM customers;) | Chapter 6 Filtering Groups with HAVING Filtering Groups with HAVING The HAVING clause sets conditions on the GROUP BY clause similar to the way that WHERE interacts with SELECT. The HAVING clause s important characteristics are The HAVING clause comes after the GROUP BY clause and before the ORDER BY clause. Just as WHERE limits the number of rows displayed by SELECT HAVING limits the number of groups displayed by GROUP BY. The WHERE search condition is applied before grouping occurs and the HAVING search condition is applied after. HAVING syntax is similar to the WHERE syntax except that HAVING can contain aggregate functions. A HAVING clause can reference any of the items that appear in the SELECT list. The sequence in which the WHERE GROUP BY and HAVING clauses are applied is 1. The WHERE clause filters the rows that result from the operations specified in the FROM and JOIN clauses. 2. The GROUP BY clause groups the output of the WHERE clause. 3. The HAVING clause filters rows from the grouped result. Listing List the number of books written or cowritten by each author who has written three or more books. See Figure for the result. Listing SELECT au_id COUNT AS num_books FROM title_authors GROUP BY au_id HAVING COUNT 3 au_id num_books A01 3 A02 4 A04 4 A06 3 Figure Result of Listing . Listing List the number of titles and average revenue for the types with average revenue more than 1 million. See Figure for the result. Listing SELECT type COUNT price AS COUNT price AVG price sales AS AVG revenue FROM titles GROUP BY type HAVING AVG price sales 1000000 type COUNT price AVG revenue biography 3 computer 1 Figure Result of Listing . 190 Summarizing and Grouping Data Listing Listing still works without AVG price sales in the SELECT list. See Figure for the result. Listing SELECT type COUNT price AS COUNT price FROM titles GROUP BY type HAVING AVG price sales 1000000 type COUNT price biography

TỪ KHÓA LIÊN QUAN
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.