1. 程式人生 > >MYSQL 部分練習題

MYSQL 部分練習題

mil mar name datetime style 公司 ins 查詢 insert

在三個表的基礎上:

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 部分練習題