oracle数据库面试题,如下,求解!

2025-02-22 22:41:28
推荐回答(1个)
回答1:

1
product主键id
顾客表主键acid
商品交易表为联合主键(acid+id),同时acid和id分别是顾客表和商品表的外键

2
select b.acname,b.acadress
from product a,customer b,order c where a.id=c.id and b.acid=c.acid
and a.name='李子'

3
select t1.acname
from
(select b.acname
from product a,customer b,order c where a.id=c.id and b.acid=c.acid
and a.name='李子') t1,
(select b.acname
from product a,customer b,order c where a.id=c.id and b.acid=c.acid
and a.name='苹果') t2
where t1.acname=t2.acname



4
select b.acname,
sum(case when type='家电' then a.price*c.amount else 0 end) as 家电价格,
sum(case when type='水果' then a.price*c.amount else 0 end) as 水果价格
from product a,customer b,order c where a.id=c.id and b.acid=c.acid
group by b.acname