feat(DB): lab 1 2
This commit is contained in:
parent
7e9fd20025
commit
3053debba8
2 changed files with 72 additions and 0 deletions
41
DB/exp1.sql
Normal file
41
DB/exp1.sql
Normal file
|
@ -0,0 +1,41 @@
|
|||
create database eshop4490;
|
||||
|
||||
create table members(
|
||||
m_account varchar(20) primary key,
|
||||
m_name varchar(20),
|
||||
m_sex varchar(2),
|
||||
m_address varchar(50),
|
||||
m_salary money,
|
||||
m_password varchar(20)
|
||||
);
|
||||
create table products(
|
||||
p_no char(10) primary key,
|
||||
p_name varchar(30),
|
||||
p_quantity int,
|
||||
p_price money,
|
||||
p_information varchar(50)
|
||||
);
|
||||
create table orders(
|
||||
m_account varchar(20) references members(m_account),
|
||||
p_no char(10) references products(p_no),
|
||||
o_quantity int,
|
||||
o_date date
|
||||
);
|
||||
|
||||
insert into members values ('jin', '刘津', '女', '北京', 8200, 'jin'),
|
||||
('lfz', '刘法制', '男', '天津', 4500, 'lfz'),
|
||||
('jinjin', '津津', '女', '北京', 8200, 'jin'),
|
||||
('liuzc', '刘志成', '男', '湖南株洲', 3500,'liuzc'),
|
||||
('Wangym', '王咏梅', '女', '湖南长沙', 4000, 'wangym');
|
||||
insert into products values ('101', '香皂', 22, 6, '清洁用品'),
|
||||
('102', '牙刷', 10, 20, '价廉物美'),
|
||||
('103', 'MP3', 100, 450, '电子产品'),
|
||||
('104', '毛巾', 10,15, '价廉物美');
|
||||
insert into orders values ('lfz', '101', 5, '2017-8-9'),
|
||||
('Wangym', '101',9, '2017-6-6'),
|
||||
('jinjin', '102', 6, '2017-6-6'),
|
||||
('liuzc', '102', 4, '2017-8-9'),
|
||||
('Wangym', '103', 7, '2017-8-9'),
|
||||
('jinjin', '103', 6, '2017-8-9');
|
||||
|
||||
update members set m_salary = m_salary * 1.2 WHERE m_sex = '女' and m_address ='北京';
|
31
DB/exp2.sql
Normal file
31
DB/exp2.sql
Normal file
|
@ -0,0 +1,31 @@
|
|||
select * from members where m_address like '%湖南%';
|
||||
|
||||
|
||||
select p_no, SUM(o_quantity) as total_quantity
|
||||
from orders group by p_no
|
||||
having SUM(o_quantity) > 5
|
||||
order by total_quantity desc;
|
||||
|
||||
select m_account,p_no from orders where p_no in (select p_no from orders where m_account = 'Wangym') and m_account != 'Wangym';
|
||||
|
||||
create view View1 as
|
||||
select * from members
|
||||
where m_account in (select m_account from orders where p_no = '102');
|
||||
|
||||
insert into View1 values ('fengx','冯向','男','北京',5000,'fx');
|
||||
|
||||
|
||||
select m.*, o.o_quantity, o.o_date, o.p_no
|
||||
from members m
|
||||
left join orders o on m.m_account = o.m_account;
|
||||
|
||||
update members
|
||||
set m_password = 'liu'
|
||||
where m_account = 'liuzc';
|
||||
|
||||
insert into members values ('liuzc','翁红','男','湖南株洲','5500','123');
|
||||
|
||||
alter table members add constraint m_sex_check check (m_sex in('男','女'));
|
||||
insert into members values ('liuzh','刘忠怀','工','湖南株洲',3000,'liuzh');
|
||||
|
||||
insert into orders values ('Zhou','101',1, '2017-8-9');
|
Reference in a new issue