TAILIEUCHUNG - Pro MySQL experts voice in open source phần 7

Tham khảo tài liệu 'pro mysql experts voice in open source phần 7', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 430 CHAPTER 12 VIEWS Listing 12-12. Output of a View with a HAVING Clause mysql SELECT FROM small_ship_dates ------------ ----------------- ship_date number_of_orders ------------ ----------------- 2005-08-27 1 2005-08-28 1 2005-08-31 1 2005-09-10 1 2005-09-27 1 ------------ ----------------- 5 rows in set sec Unioned Tables Views can also be created by two or more SELECT statements joined together with a UNION statement. As explained in Chapter 7 the UNION statement allows you to join multiple queries that have the same fields. To illustrate how multiple SQL statements might be joined with a UNION suppose our online ordering system forwards the order to a certain fulfillment center based on the geographic location of the person placing the order. Each center keeps a separate record of the customers. We want to provide a way to query customers across all centers so we pull their databases onto a single server and create a view that centralizes their databases onto a single table using a UNION statement. Listing 12-13 shows a sample of the customer table from the region 1 database. Listing 12-13. Sample Customer Database from Region 1 mysql SELECT FROM ------------ ---------- customer_id name ------------ ---------- 1 Mike 2 Jay ------------ ---------- 2 rows in set sec We can easily create a view that pulls data from all three regions with the CREATE statement shown in Listing 12-14. Listing 12-14. Creating a View with UNION mysql CREATE VIEW all_customers AS SELECT FROM UNION SELECT FROM UNION SELECT FROM CHAPTER 12 VIEWS 431 A simple SELECT statement will now present results from all three tables as shown in Listing 12-15. Listing 12-15. Output of Selecting from the View Created with UNION mysql SELECT FROM all_customers customer_id name 1 Mike 2 Jay 3 Johanna 4 Michael 5 Heidi 6 Ezra 6 rows in set sec Listing 12-15 offers a convenient snapshot of the customer data pulled from the

TÀI LIỆU LIÊN QUAN
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.