Redian新闻
>
请大家帮忙看看我写的这个ORACLE查询有什么问题!!跪谢了!
avatar
请大家帮忙看看我写的这个ORACLE查询有什么问题!!跪谢了!# Database - 数据库
a*g
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');
后来我又换思路,改了一个
avatar
M*r
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

avatar
a*g
3
听起来有点复杂啊,我去试试看。多谢了,楼上的熊猫大侠。
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。