TAILIEUCHUNG - SQL Clearly Explained- P3

SQL Clearly Explained- P3: You don’t need to be a database designer to use SQL successfully. However, you do need to know a bit about how relational databases are structured and how to manipulate those structures. | 98 Chapter 4 Simple SQL Retrieval isbn 978-1-11111-146 1 978-1-11111-122 1 978-1-11111-130 1 978-1-11111-126 1 978-1-11111-139 1 Figure 4-9 Displaying a single column from multiple rows using a SELECT isbn FROM volume WHERE sale_id 6 AND selling_price asking_price Only two rows meet the criteria isbn 978-1-11111-130-1 978-1-11111-139-1 By the same token if you wanted to see all sales that took place prior to August 1 2013 and for which the total amount of the sale was less than 100 the query would be written SELECT sale_id sale_total_amt FROM sale WHERE sale_date 1-Aug-2012 AND sale_total_amt 100 It produces the result in Figure 4-10. Note Don t forget that the date format required by your DBMS may be different from the one used in examples in this book. Alternatively if you needed information about all sales that occurred prior to or on August 1 2013 that totaled more than 100 along with sales that occurred after August 1 2013 that totaled less than 100 you would write the query Please purchase PDF Split-Merge on to remove this watermark. Choosing Rows 99 sale_id sale_total_amt 3 7 8 9 13 14 15 Figure 4-10 Retrieving rows using a complex predicate including a date SELECT sale_id sale_date sale_total_amt FROM sale WHERE sale_date 1-Aug-2013 AND sale_total_amt 100 OR sale_date 1-Aug-2013 AND sale_total_amt 100 Notice that although the AND operator has precedence over OR and therefore the parentheses are not strictly necessary the predicate in this query includes parentheses for clarity. Extra parentheses are never a problem as long as you balance every opening parenthesis with a closing parenthesis and you should feel free to use them whenever they help make it easier to understand the meaning of a complex predicate. The result of this query can be seen in Figure 4-11. As an example of using one of the special predicate operators consider a query where someone wants to see all sales that occurred between July

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