考虑以下架构:
Suppliers(sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog(sid: integer, pid: integer, cost: real)
目录关系列出了供应商为零件收取的价格。
我有两个问题:
这是到目前为止我尝试过的事情:
select s.sname, count(*)
from suppliers s, parts p, catalog c
where p.pid = c.pid and c.sid = s.sid
group by s.sname, s.sid
having every (p.color = 'green')
和
select s.sname, max(c.cost)
from suppliers s, parts p, catalog c
where p.pid = c.pid and c.sid = s.sid
group by s.sname, s.sid
having some (p.color = 'green') and some (p.color = 'red')
当我执行上述两个查询时,查询输出显示缺少右括号,需要帮助谢谢。
答案 0 :(得分:0)
Oracle中没有every
也没有some
(至少在11g中没有),因此您的having
子句都不正确。
答案 1 :(得分:0)
您可以清楚地计数绿色部分:
select s.sname, count(distinct p.pid) as "Total #of Parts"
from suppliers s
join catalog c on c.sid = s.sid
join parts p on p.pid = c.pid
group by s.sname
having count(distinct case when p.color = 'green' then 1 end ) = 1
在第二种情况下,您可以考虑至少一个绿色部分和至少一个红色部分:
select s.sname, max(c.cost) as "Max Price"
from suppliers s
join catalog c on c.sid = s.sid
join parts p on p.pid = c.pid
group by s.sname
having count(case when p.color = 'green' then 1 end ) > 0
and count(case when p.color = 'red' then 1 end ) > 0
every
和some
是Oracle SQL中的无效关键字。