CSC 4402 20090928

CSC 4402 20090928 - select br_name from branch where br_city=’BTR’ except/minus select branch.br_name from account,depositor where

Info iconThis 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
Background 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

This note was uploaded on 01/25/2010 for the course CSC 4402 taught by Professor Staff during the Fall '08 term at LSU.

Ask a homework question - tutors are online