Joe Celko s SQL for Smarties - Advanced SQL Programming P65

Joe Celko s SQL for Smarties - Advanced SQL Programming P65. 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. | 612 CHAPTER 27 SUBSETS SELECT MIN keycol MAX keycol - MIN keycol RANDOM FROM LotteryDrawing AS L2 Here is a version which uses the count functions and a self-join instead. SELECT Ll. FROM LotteryDrawing AS L1 WHERE CEILING SELECT COUNT FROM LotteryDrawing RANDOM SELECT COUNT FROM LotteryDrawing AS L2 WHERE The rounding away from zero is important since we are in effect numbering the rows from one. The idea is to use the decimal fraction to hit the row that is far into the table when the rows are ordered by the key. Having shown you this code I have to warn you that the pure SQL has a good number of self-joins and they will be expensive to run. The CONTAINS Operators Set theory has two symbols for subsets. One c means that set A is contained within set B this is sometimes said to denote a proper subset. The other means is contained in or equal to and is sometimes called just a subset or containment operator. Standard SQL has never had an operator to compare tables against each other for equality or containment. Several college textbooks on relational databases mention a CONTAINS predicate which does not exist in Standard SQL. This predicate existed in the original System R IBM s first experimental SQL system but it was dropped from later SQL implementations because of the expense of running it. Proper Subset Operators The in predicate is a test for membership. For those of you who remember your high school set theory membership is shown with a stylized epsilon with the containing set on the right side a G A. Membership is for one element whereas a subset is itself a set not just an element. As an example of a subset predicate consider a query to tell The CONTAINS Operators 613 you the names of each employee who works on all of the projects in department 5. Using the System R syntax SELECT name Not valid SQL FROM Personnel WHERE SELECT project_nbr FROM WorksOn WHERE CONTAINS SELECT project_nbr .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.