北大“数据库原理”上机实践题目总结(9)
3 完成以下查询:
(1)存款余额大于1000的存款单编号。
select ano
from account
where money>1000
(2)列出拥有存款单的张数更多的客户的客户号。
select cno
from custacc
group by cno
having count(ano)>=all
(select count(ano)
from custacc
group by cno)
(3)统计每个地区的客户存款总额。
select addr,sum(money)
from customer c,account a,custacc ca
where c.cno=ca.cno and a.ano=ca.ano
group by addr
4 客户101 在属于它的每个存款单上都存入100元。
update account
set money=money+100
where ano in
(select ano
from custacc
where cno ='101')
5 清除那些不被任何客户拥有的存款单。
delete from account
where ano not in
(select ano
from custacc)
赛马(赛马编号,赛马颜色,赛马产地)
比赛记录(场次,获胜赛马编号)
投注记录(场次,会员编号,所选赛马编号)
投注过程:每场,会员可以投一匹马,投注化2元,获胜可以得到10元奖励。
要求:1 建表,要定义以下声名:
a)必要的主,外码
b)会员姓名,所在地,赛马颜色,产地不能为空。
c)会费余额不能小于0.
2 插入数据,(注意给定数据的日期插入时必须转换为合适的格式)
插入条目发到下一帖中,是为了让大家尽快看到体型,请多原谅。
3 a)找出所在地在北京的,会员余额大于10的会员。
b)找出赛马中获胜次数更多的产地。
c)找出投注次数更多的会员。
4 会员韩家,编号为u003)在第四场中给h004的马投注了,请更新数据库。
5 使用游标确定赚钱更多的用户(只考虑获得的奖励)
6 算出马场主在所有的比赛中赚了多少钱。