lec10.365.worksheet

lec10.365.worksheet - . . Fall 2007 CPE/CSC 365:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: . . Fall 2007 CPE/CSC 365: Introduction to Database Systems Alexander Dekhtyar . . SQL: Structured Query Language Grouping Queries: Example How Grouping works Consider two relations R(A,B,C) and S(B,D) (all attributes are integer). Con- sider the following instances of tables R and S : R A B C 1 2 2 1 4 4 2 2 5 3 4 8 2 4 1 3 4 12 S B D 2 1 4 7 Consider the following SQL query SELECT R.A, SUM(R.B), AVG(R.C), COUNT(*), MIN(S.D) FROM R, S WHERE R.B = S.B and R.C < 10 GROUP BY R.A HAVING COUNT(*) > 1; This query is evaluated as follows. Step 1. FROM Clause: Cartesian Product. First, the FROM clause is evalu- ated. It is convenient to view thist step as creation of a cartesian product of all tables referenced in the FROM clause. Here, this leads to computation of R × S : 1 R × S R.A R.B R.C S.B S.D 1 2 2 2 1 1 4 4 2 1 2 2 5 2 1 3 4 8 2 1 2 4 1 2 1 3 4 12 2 1 1 2 2 4 7 1 4 4 4 7 2 2 5 4 7 3 4 8 4 7 2 4 1 4 7 3 4 12 4 7 Step 2: WHERE Clause: Join and selection. On this step, each tuple in the cartesian product constructed on the previous step is evaluated against the conditions specified in the WHERE clause....
View Full Document

This note was uploaded on 05/19/2008 for the course CSC 365 taught by Professor Dekhtyar during the Spring '08 term at Cal Poly.

Page1 / 4

lec10.365.worksheet - . . Fall 2007 CPE/CSC 365:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online