Đang chuẩn bị liên kết để tải về tài liệu:
Joe Celko s SQL for Smarties - Advanced SQL Programming P45

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

Joe Celko s SQL for Smarties - Advanced SQL Programming P45. 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 audience. | 412 CHAPTER 19 PARTITIONING DATA IN QUERIES WHERE Sl.sup S2.sup different suppliers AND Sl.part S2.part same parts GROUP BY Sl.sup S2.sup HAVING COUNT SELECT COUNT -- same count of parts FROM SupParts AS S3 WHERE S3.sup Sl.sup AND COUNT SELECT COUNT FROM SupParts AS S4 WHERE S4.sup S2.sup This can be modified into Todd s division easily by adding the restriction that the parts must also belong to a common job. Steve Kass came up with a specialized version that depends on using a numeric code. Assume we have a table that tells us which players are on which teams. CREATE TABLE TeamAssignments player_id INTEGER NOT NULL REFERENCES Players player_id ON DELETE CASCADE ON UPDATE CASCADE team_id CHAR 5 NOT NULL REFERENCES Teams team_id ON DELETE CASCADE ON UPDATE CASCADE PRIMARY KEY player_id team_id To get pairs of players on the same team SELECT P1.player_id P2.player_id FROM Players AS Pl Players AS P2 WHERE P1.player_id P2.player_id GROUP BY P1.player_id P2.player_id HAVING P1.player_id P2.player_id ALL SELECT SUM P3.player_id FROM TeamAssignments AS P3 WHERE P3.player_id IN P1.player_id P2.player_id GROUP BY P3.team_id 19.2 Relational Division 413 19.2.5 Division with JOINs Standard SQL has several join operators that can be used to perform a relational division. To find the pilots who can fly the same planes as Higgins use this query SELECT SP1.Pilot FROM SELECT plane FROM Hangar AS H1 INNER JOIN SELECT pilot plane FROM PilotSkills AS SP1 ON H1.plane SP1.plane INNER JOIN SELECT FROM PilotSkills WHERE pilot Higgins AS H2 ON H2.plane H1.plane GROUP BY Pilot HAVING COUNT SELECT COUNT FROM PilotSkills WHERE pilot Higgins The first join finds all of the planes in the hangar for which we have a pilot. The next JOIN takes that set and finds which of those match up with SELECT FROM PilotSkills WHERE pilot Higgins skills. The group by clause will then see that the intersection we have formed with the joins has at least as many elements as Higgins has planes. The group by .

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