MYSQL 部分练习题
Posted Hipper
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL 部分练习题相关的知识,希望对你有一定的参考价值。
在三个表的基础上:
create table customer(
id varchar(10) primary key,
name varchar(16),
sex varchar(2),
mobile varchar(11),
address varchar(50),
);
create table OrderBook(
csid varchar(10),
cmid varchar(12),
count int(11),
bookdate datetime,
takedate datetime,
check(takedate>bookdate),
check(count>0),
foreign key(csid) references Customer(id),
foreign key(cmid) references Commodity(id),
primary key(csid,cmid)
);
create table Commodity(
ID varchar(12) primary key,
name varchar(20) not null,
manufacture varchar(20),
price decimal(4,2)
);
1. 往基本表Customer中插入顾客元组(”0421F901”,”WU”,”女”,13980011001)
insert into customer values("0421f901","wu","女",13980011001);
2. 往基本表Commodity中插入一条商品记录(“03110408591”,“牙膏”,“保洁公司”,5.00)
insert into commodity values("03110408591","牙膏","保洁公司",5.00);
3. 修改“WANGYAN”顾客定购商品的记录交货日期为2005-12-25。
update Orderbook set takedate=‘2005-12-25‘ where csid=(select id from custmoer where name = "WANGYAN");
4. 把“雀巢奶粉”的定购商品记录全部删去。
delete count,bookdate,takedate from orderbook where csid=(select id from
commodity where name="雀巢奶粉");
5. 查询“ANAN”顾客的手机号和住址。
select mobile,address from customer where name="ANAN";
6. 查询商品的平均价格高于75元钱的厂商名称。
select MANUFACTURE from Commodity where PRICE in (select avg(PRICE) from Commodity and avg(PRICE)>75);
7. 查询顾客的定购信息,并按订货日期升序排列,若订货日期相同,则按定购数量降序排列。
select * from orderbook order by bookdate asc,count desc;
以上是关于MYSQL 部分练习题的主要内容,如果未能解决你的问题,请参考以下文章