03 - SQL

03 - SQL - CSE 135 Discussion Section SQL Yupeng Fu...

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

View Full Document Right Arrow Icon
CSE 135 Discussion Section SQL Yupeng Fu [email protected]
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Relational schema (lecture) id pid first_name last_name 1 8888888 John Smith 2 1111111 Mary Doe 3 2222222 Jay Chen Students id name number date_code start_time end_tim e 1 Web stuff CSE135 TuTh 2:00 3:20 2 Databases CSE132A TuTh 3:30 4:50 4 VLSI CSE121 F 11:00 12:00 Classes id class student credits 1 1 1 4 2 1 2 3 3 4 3 4 4 1 3 3 Enrollment
Background image of page 2
3 SQL problem (lecture) Problem: List students’ id,name and the number of total credits for which they have registered no less than 4 credits SELECT s.id, s.first_name, s.last_name, SUM(e.credits) FROM students AS s, enrollment AS e WHERE s.id = e.student GROUP BY s.id, s.first_name, s.last_name HAVING SUM(e.credits)>= 4
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Meaning of SQL query? database students enrollment classes query view
Background image of page 4
5 FROM clause Perform combinations Problem: List all students and the enrollment Tip: Use aliases (even when they are optional) Alias is referred as tuple variable
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 WHERE clause Keep the tuples that satisfy the conditions Problem: List all students and their registration Tip: Never forget join condition
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/31/2011 for the course CSE 135 taught by Professor Papakonstantinou during the Fall '10 term at UCSD.

Page1 / 11

03 - SQL - CSE 135 Discussion Section SQL Yupeng Fu...

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

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