0
点赞
收藏
分享

微信扫一扫

MySQL实训_01


1.创建数据库,名称为qfdb;(如果已有,则省略)

create database if not exists qfdb;

 2.创建数据表customer(客户)、deposite(存款)、bank(银行),表结构如下:

MySQL实训_01_mysql

 

-- 创建表customer(客户),deposite(存款),bank(银行)
create table if not exists customer
(c_id char(6) not null comment '客户标识',
name varchar(30) not null comment '客户姓名',
location varchar(30) comment '工作地点',
salary decimal(8,2) comment '工资',
primary key (c_id));


-- 创建表bank
create table if not exists bank
(b_id char(5) not null comment '银行标识',
bank_name char(30) not null comment '银行名次',
primary key(b_id)
);

-- 创建表deposite
create table if not exists deposite
(
d_id int not null auto_increment comment '存款流水号',
c_id char(6) not null comment '客户标识',
b_id char(5) not null comment '银行标识',
dep_date date comment '存入日期',
dep_type char(1) comment '存款期限',
amount decimal(8,2) comment '存款金额',
primary key (d_id),
foreign key (c_id) references customer (c_id),
foreign key (b_id) references bank (b_id)
);

3.录入数据

MySQL实训_01_数据_02

MySQL实训_01_mysql_03

 

  -- 插入customer数据
insert into customer values
(101001,'孙杨','广州','1234'),
(101002,'郭海','南京','3526'),
(101003,'卢江','苏州','6892'),
(101004,'郭惠','济南','3492'),
(101005,'谭力','北京','6324');

-- 插入bank数据
insert into bank values
('B0001','工商银行'),
('B0002','建设银行'),
('B0003','中国银行'),
('B0004','农业银行');


-- 插入deposite数据
insert into deposite values
(1,101001,'B0001','2011-04-05',3,42526),
(2,101002,'B0002','2012-07-15',5,66500),
(3,101003,'B0003','2010-11-24',1,42366),
(4,101004,'B0004','2008-03-31',1,62362),
(5,101001,'B0001','2002-02-07',3,56346),
(6,101002,'B0002','2004-09-23',3,353626),
(7,101003,'B0003','2003-12-14',5,36236),
(8,101004,'B0004','2007-04-21',5,26267),
(9,101001,'B0001','2011-02-11',1,425456),
(10,101002,'B0002','2012-05-13',1,234626),
(11,101003,'B0003','2001-01-24',5,26243),
(12,101004,'B0004','2009-08-23',3,45671);

4.更新customer表的salary属性,将salary低于5000的客户的salary变为原来的2倍.

-- 4.更新customer表的salary属性
update customer set salary=salary*2 where salary < 5000;

5.对deposite表进行统计,按银行统计存款总数,显示为b_id,total.

-- 5.对deposite表进行统计,按银行统计存款总数,显示为b_id,total.
select b_id,sum(amount) as total from deposite group by b_id;

6.对deposite、customer、bank进行查询,查询条件为location在广州、苏州、济南的客户,存款在300000至500000之间的存款记录,显示客户姓名name、银行名称bank_name、存款金额amount.

-- 6.对deposite、customer、bank进行查询,查询条件为location在广州、苏州、济南的客户,
-- 存款在300000至500000之间的存款记录,
-- 显示客户姓名name、银行名称bank_name、存款金额amount.
select name,bank_name,amount from
deposite inner join bank on deposite.b_id = bank.b_id inner join customer on deposite.c_id = customer.c_id where customer.location in ('广州','苏州','济南') and deposite.amount between 300000 and 500000;

举报

相关推荐

实训5.3

实训4.1

实训5.2

坦克实训

项目实训(三)

hadoop实训心得

Python实训题目

0 条评论