a******g 发帖数: 13519 | 1 查询涉及两个表:account(A#,cname,bname,bal), branch(bname,assets,bcity)
查询要求 print the name of all customers who have an account at every branch
in “Edina” where “James” does not have an account.
我的代码如下(老师说是错误的,结果对但代码表达的意思不对)
SELECT distinct cname
FROM account
WHERE bname
IN
(SELECT bname
FROM branch
WHERE lower(bcity) = 'edina')
MINUS
SELECT distinct cname
FROM account
WHERE bname
IN
(SELECT distinct account.bname
FROM account, branch
WHERE lower(cname) = 'james'
And lower(bcity)='edina');
后来我又换思路,改了一个 | M*****r 发帖数: 1536 | 2 比如,得到满足(branch in “Edina” where “James” does not have an account
)条件的distinct的branch的数目
然后按上面branch的条件和account表join,select account.cname, count(distinct
bname) group by account.cname having count(distinct bname) = 前面的数目
branch
【在 a******g 的大作中提到】 : 查询涉及两个表:account(A#,cname,bname,bal), branch(bname,assets,bcity) : 查询要求 print the name of all customers who have an account at every branch : in “Edina” where “James” does not have an account. : 我的代码如下(老师说是错误的,结果对但代码表达的意思不对) : SELECT distinct cname : FROM account : WHERE bname : IN : (SELECT bname : FROM branch
| a******g 发帖数: 13519 | 3 听起来有点复杂啊,我去试试看。多谢了,楼上的熊猫大侠。 |
|