{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CSC 4402 20090928

CSC 4402 20090928 - select br_name from branch where...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CSC 4402 9/28/2009 Page 1 of 1 Homework 4, question 2 – use select subquery by selecting from EM where CITY=”New Orleans”. SELECT SSN, (AAA), (BBB), FROM em WHERE city=’New Orleans’; AAA = SELECT AVG(grade) FROM ER WHERE ER.SSN = EM.SSN AS AVERAGE; BBB = SELECT count(*) FROM ER WHERE ER.SSN = EM.SSN AS NUM_COURSES; Banking example -- Getting cus_name for customers who have a deposit account in every branch in BTR: With double negation: Select cus_name from customer where not exists ( select br_name from branch where br_city=’BTR’ AND not exists ( select * from account, depositor where depositor.cus_name = customer.cus_name AND account.br_name = branch.br_name AND depositor.acct_num = account.acct_num ) ) With set difference: Select cus_name from customer where not exists
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ( select br_name from branch where br_city=’BTR’ except/minus ( select branch.br_name from account,depositor where account.acct_num = depositor.acct_num AND depositor.cus_name = customer.cus_name ) ) With “positive logic” – where the number of accounts in branches in BTR = number of branchesin BTR Select cus_name from customer where ( select count(*) from branch where br_city=’BTR’ ) = ( select count(distinct br_name) from depositor, account where depositor.acct_num = acct.acct_num AND customer.cus_name = depositor.cus_name AND br_name in ( select br_name from branch where br_city=’BTR’) ) Derived relation example – simpler, cleaner query Select br_name, avg(balance) as avg_b from account group by br_name having avg(balance) > 1200...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern