The Language of SQL- P19

The Language of SQL- P19:Research has shown that, being pressed for time, most readers tend to skip the introduction of any book they happen to read and then proceed immediately to the first real chapter. With that fact firmly in mind, we will only cover relatively unimportant material in the introduction, such as an explanation of what you will and will not learn by reading this book. | 76 Chapter 8 Boolean Logic The result is CustomerName State QuantityPurchased William Smith IL 4 Brenda Harper NY 5 Notice there are two sets of parentheses in this statement. Our use of parentheses here is analogous to the parentheses used in the composite functions seen in Chapter 4. With regard to functions if there is more than one set of parentheses the innermost set of functions always gets evaluated first. The same is true of parentheses used in Boolean expressions. In this example the innermost set of parentheses contains QuantityPurchased 3 AND QuantityPurchased 10 After this is evaluated for each row you can then proceed outward to the second set of parentheses State IL AND QuantityPurchased 3 AND QuantityPurchased 10 Finally you add in the final line in the WHERE clause which is not enclosed in any parentheses at all WHERE State NY OR State IL AND QuantityPurchased 3 AND QuantityPurchased 10 The NOT Operator In addition to the AND and OR operators it is often useful to use the NOT operator to express a complex logical condition. The NOT expresses a negation or opposite of whatever follows the NOT. Here s a simple example SELECT CustomerName State The NOT Operator 77 QuantityPurchased FROM Orders WHERE NOT State NY The result is CustomerName State QuantityPurchased William Smith IL 4 Natalie Lopez CA 10 This specifies a selection of rows where the state is not equal to NY. In this simple case the NOT operator is not truly necessary. The previous statement can also be accomplished via the following equivalent statement SELECT CustomerName State QuantityPurchased FROM Orders WHERE State NY In this situation the not equals operator accomplishes the same thing as the NOT operator. Here s a more complex example with the NOT operator SELECT CustomerName State QuantityPurchased FROM Orders WHERE NOT State IL OR State NY The result is CustomerName State QuantityPurchased Natalie Lopez CA 10 78 Chapter 8 Boolean Logic When the NOT operator is used before a set of

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
110    110    5    02-07-2024
Đã 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.