"MYSQL Advanced Query and Programming" Comprehensive Test Paper-Yunnan Agricultural Vocational Beauty and Yisi

Topic: Bank mys q l database system management

table of Contents

Topic: Bank mysql database system management

1. Language and environment

2. Topic (100 points):

Functional Requirements:

Claim:

3. Submission method

Four, scoring standards:

5. Implementation code:

Create the table structure:

Insert data:

1. Make statistics on the deposit table, count the total number of deposits by bank, and display them as b_id, bank_name, total; (Note: save the result as a view, and screenshot the result, name the view and picture as answer01);

2. Query deposit, customer, bank. The query conditions are customers whose locations are in Guangzhou, Suzhou and Jinan, and deposit records with deposits between 300,000 and 500,000, showing the customer name, bank name, and deposit amount; The result is saved in the view; (Note: Save the result as a view, and a screenshot of the result, the view and picture are named answer02)

3. Query the deposit information of the top 2 customers in the Agricultural Bank of China (display information: customer name, bank name, deposit amount); (Note: save the result as a view, and the screenshot of the result, the view and picture are named answer03);

4. Update the salary attribute of the customer table to double the salary of customers whose salary is less than 5000 (Note: execute the sql statement you have written, check the result change, no need to save the sql, save the screenshot of the data before the update Is answer04(old), the updated data screenshot is answer04(new)); 

5. The query date is from the date of 2011-04-05 to the current customer ID, customer name, bank name, deposit amount, in descending order of deposit amount; save the result in the view (Note: save the result as a view And name the result screenshot, view and picture answer05);

6. Query Guo Hai’s deposit information in ICBC (display information: customer id, customer name, bank ID, bank name, deposit date, deposit amount) (Note: save the result as a view, and screenshot the result, view and picture Named answer06);

7. Create a stored procedure, use the int type to pass in the parameter 10000, and query the name, amount, and deposit period of customers whose deposits in ICBC are greater than or equal to 10,000 (the query is implemented using table links and sub-queries) (Note: the sql statement is. Save the txt file and name it answer07);

The complete structure and code of the database:


1. Language and environment

  1. Implementation language: sql.
  2. Development environment: mySql, navicat.

2. Topic (100 points):

Functional Requirements:

a. Create a database and name it myBank;

b. Create data tables customer (customer), deposit (deposit), bank (bank), the table structure is as follows:

Customer table structure

deposite table structure

Bank table structure

 c. Enter the following data

The customer data is as follows:

The bank data is as follows:

The deposite data is as follows:

Claim:

  1. Perform statistics on the deposit table, count the total number of deposits by bank, and display them as b_id, bank_name, total; ( Note : save the result as a view, and take a screenshot of the result, name the view and picture as answer01 ) ;
  2. Query deposit, customer, bank, query conditions are customers whose locations are in Guangzhou, Suzhou, Jinan, deposit records between 300,000 and 500,000, display customer name, bank name, and deposit amount; save the result In the view; ( Note : save the result as a view, and take a screenshot of the result, and name the view and picture as answer 02 )
  3. Query the deposit information of the top 2 customers in the Agricultural Bank of China (display information: customer name, bank name, deposit amount); ( Note : save the result as a view, and the result screenshot, view and picture named answer03 );
  4. Update the salary attribute of the customer table to double the salary of customers whose salary is less than 5000 ( Note : execute the sql statement you have written, check the result change, no need to save the sql , save the data screenshot before the update as answer 04(old) , the updated data screenshot is answer 04( new ) ); 
  5. The query date is from the date of 2011-04-05 to the current customer ID, customer name, bank name, deposit amount, in descending order of deposit amount; save the result in the view ( Note : save the result as a view, and Name the result screenshot, view and picture answer05 );
  6. Query Guo Hai’s deposit information in ICBC (display information: customer id, customer name, bank ID, bank name, deposit date, deposit amount) ( Note : save the result as a view, and name the screenshot, view and picture as answer06 );
  7. Create a stored procedure, use the int type to pass in the parameter 10000, and query the name, amount, and deposit period of customers whose deposits at ICBC are greater than or equal to 10,000 (the query is implemented using table links and sub-queries) ( Note : SQL statements are in .txt files Save it and name it answer07 );

Note: There are 2 ways to save as a view:

一、create view view_name as select column_name from table_name  where condition;

2. Use the tool to create a view and save it;

Recommended implementation steps

  1. Open Navicat and create the database myBank;
  2. Create data tables customer (customer), deposit (deposit), bank (bank), pay attention to the primary key, foreign key and related constraints, type and length when building the table, and enter the data according to the above table data (sql statement can be used, or Use Navicat to fill in the data directly).
  3. Complete the query and modify as required. Save the query or view of the SQL statement according to the corresponding remarks; the SQL statement can be externally linked or sub-queried, and the method is not limited; the view can be created directly with the Navicat view tool or by writing code.

3. Submission method

The file is submitted as a compressed package. The compressed file naming method: student ID + Chinese name.zip, for example: 193610202139 张玉苗.zip, the compressed package must be submitted within the specified time and in accordance with the requirements of the invigilator.

Four , scoring standards:

Topic: Bank Management System

The scoring criteria for the program are as follows:

30

The correct creation of the database and table structure, and the correct data entry according to the prompts

 

5

Database creation (including naming)

 

15

Create the table structure correctly (including table naming and primary key, external inspection and non-empty constraints)

 

10

Enter data correctly

70

Query or modify and save the query or create a view as required

 

10

Requirement 1, the result is correct

 

10

 

Requirement 2, the result is correct

 

10

Requirement 3, the result is correct

 

10

Requirement 4, the result is correct

 

10

Requirement 5, the result is correct

 

10

Requirement 6, the result is correct

 

10

Requirement 7, the result is correct

Total score

100 points

5. Implementation code:

Create the table structure:

-- ----------------------------
-- Table structure for bank
-- ----------------------------
CREATE TABLE `bank` (
  `b_id` char(5) NOT NULL,
  `bank_name` char(30) NOT NULL,
  PRIMARY KEY (`b_id`)
);
-- ----------------------------
-- Table structure for customer
-- ----------------------------
CREATE TABLE `customer` (
  `c_id` char(6) NOT NULL,
  `name` varchar(30) NOT NULL,
  `location` varchar(30) DEFAULT NULL,
  `salary` double(8,2) DEFAULT NULL,
  PRIMARY KEY (`c_id`)
);
-- ----------------------------
-- Table structure for deposite
-- ----------------------------
CREATE TABLE `deposite` (
  `d_id` int(11) NOT NULL,
  `c_id` char(6) DEFAULT NULL,
  `b_id` char(5) DEFAULT NULL,
  `dep_date` date DEFAULT NULL,
  `dep_type` int(11) DEFAULT NULL,
  `amount` double(10,3) DEFAULT NULL,
  PRIMARY KEY (`d_id`)
);

Insert data:

bank table:

INSERT INTO `bank` VALUES ('B0001', '工商银行');
INSERT INTO `bank` VALUES ('B0002', '建设银行');
INSERT INTO `bank` VALUES ('B0003', '中国银行');
INSERT INTO `bank` VALUES ('B0004', '农业银行');

customer表:

INSERT INTO `customer` VALUES ('101001', '孙杨', '广州', '1234.00');
INSERT INTO `customer` VALUES ('101002', '郭海', '南京', '3526.00');
INSERT INTO `customer` VALUES ('101003', '卢江', '苏州', '6892.00');
INSERT INTO `customer` VALUES ('101004', '郭惠', '济南', '3492.00');

deposite table:

INSERT INTO `deposite` VALUES ('1', '101001', 'B0001', '2011-04-05', '3', '42526.000');
INSERT INTO `deposite` VALUES ('2', '101002', 'B0003', '2012-07-15', '5', '66500.000');
INSERT INTO `deposite` VALUES ('3', '101003', 'B0002', '2010-11-24', '1', '42366.000');
INSERT INTO `deposite` VALUES ('4', '101004', 'B0004', '2008-03-31', '1', '62362.000');
INSERT INTO `deposite` VALUES ('5', '101001', 'B0003', '2002-02-07', '3', '56346.000');
INSERT INTO `deposite` VALUES ('6', '101002', 'B0001', '2004-09-23', '3', '353626.000');
INSERT INTO `deposite` VALUES ('7', '101003', 'B0004', '2003-12-14', '5', '36236.000');
INSERT INTO `deposite` VALUES ('8', '101004', 'B0002', '2007-04-21', '5', '26267.000');
INSERT INTO `deposite` VALUES ('9', '101001', 'B0002', '2011-02-11', '1', '435456.000');
INSERT INTO `deposite` VALUES ('10', '101002', 'B0004', '2012-05-13', '1', '234626.000');
INSERT INTO `deposite` VALUES ('11', '101003', 'B0003', '2001-01-24', '5', '26243.000');
INSERT INTO `deposite` VALUES ('12', '101004', 'B0001', '2009-08-23', '3', '45671.000');

1. Make statistics on the deposit table, and count the total number of deposits by bank, which is displayed as b_id, bank_name, total; ( Note : save the result as a view, and the result screenshot, the view and picture are named answer01 ) ;

CREATE VIEW answer01 AS
SELECT b.b_id b_id, b.bank_name bank_name,SUM(d.amount) total 
FROM deposite d,bank b 
WHERE d.b_id=b.b_id GROUP BY b.bank_name;

2. Query deposit, customer, bank. The query conditions are customers whose locations are in Guangzhou, Suzhou and Jinan, and deposit records with deposits between 300,000 and 500,000, showing the customer name, bank name, and deposit amount; The result is saved in the view; ( Note : save the result as a view, and take a screenshot of the result, name the view and picture as answer 02 )

CREATE VIEW answer02 AS
SELECT name 客户姓名,bank_name 银行姓名,amount 存款金额 
FROM deposite d,customer c,bank b 
WHERE b.b_id=d.b_id AND d.c_id=c.c_id 
AND location IN ('广州','苏州','济南') AND (amount BETWEEN 300000 AND 500000);

3. Query the deposit information of the top 2 customers in the Agricultural Bank of China (display information: customer name, bank name, deposit amount); ( Note : save the result as a view, and take the screenshot of the result, name the view and picture as answer03 );

CREATE VIEW answer03 AS
SELECT name 客户姓名,bank_name 银行名称,amount 存款金额 
FROM deposite d,customer c,bank b 
WHERE b.b_id=d.b_id AND bank_name='农业银行' AND d.c_id=c.c_id LIMIT 2;

4. Update the salary attribute of the customer table to double the salary of customers whose salary is less than 5000 ( Note : execute the sql statement you have written, check the result change, no need to save the sql , save the screenshot of the data before the update It is answer 04(old) , and the updated data screenshot is answer 04( new ) ); 

SELECT * FROM customer WHERE salary<5000;
UPDATE customer SET salary=(salary*2) WHERE salary<5000;
SELECT * FROM customer WHERE salary;

5. The query date is from the date of 2011-04-05 to the current customer ID, customer name, bank name, deposit amount, in descending order of deposit amount; save the result in the view ( Note : save the result as a view And name the result screenshot, view and picture answer05 );

CREATE VIEW answer05 AS
SELECT c.c_id 客户id,name 客户姓名,b.b_id 银行标识,b.bank_name 银行名称,amount 存款金额
FROM deposite d,customer c,bank b
WHERE b.b_id=d.b_id AND d.c_id=c.c_id 
AND dep_date>='2011-04-05' ORDER BY amount; 

6. Query Guo Hai’s deposit information in ICBC (display information: customer id, customer name, bank ID, bank name, deposit date, deposit amount) ( Note : save the result as a view, and screenshot the result, view and picture Named answer06 );

CREATE VIEW answer06 AS
SELECT c.c_id 客户id,name 客户姓名,b.b_id 银行标识,b.bank_name 银行名称,dep_date 存款日期,amount 存款金额
FROM deposite d,customer c,bank b
WHERE b.b_id=d.b_id AND d.c_id=c.c_id 
AND `name`='郭海' AND bank_name='工商银行';

7. Create a stored procedure, use the int type to pass in the parameter 10000, and query the name, amount, and deposit period of customers whose deposits in ICBC are greater than or equal to 10,000 (the query is implemented using table links and sub-queries) ( Note : the sql statement is. Save the txt file and name it answer07 );

-- 使用表连接查询的方式创建存储过程
delimiter $$
create procedure answer07(
	in num INT
)
begin
	SELECT name 客户姓名,amount 金额,dep_type 存款期限 
	FROM deposite d,customer c,bank b 
	WHERE b.b_id=d.b_id AND d.c_id=c.c_id  
	AND bank_name='工商银行' AND amount>=num;
end
$$
delimiter ;
-- 实现存储过程
SET @num=10000;
CALL answer07(@num);

The complete structure and code of the database:

/*
Navicat MySQL Data Transfer

Source Server         : test
Source Server Version : 50646
Source Host           : localhost:3306
Source Database       : mybank

Target Server Type    : MYSQL
Target Server Version : 50646
File Encoding         : 65001

Date: 2021-01-11 22:39:04
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for bank
-- ----------------------------
DROP TABLE IF EXISTS `bank`;
CREATE TABLE `bank` (
  `b_id` char(5) NOT NULL,
  `bank_name` char(30) NOT NULL,
  PRIMARY KEY (`b_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of bank
-- ----------------------------
INSERT INTO `bank` VALUES ('B0001', '工商银行');
INSERT INTO `bank` VALUES ('B0002', '建设银行');
INSERT INTO `bank` VALUES ('B0003', '中国银行');
INSERT INTO `bank` VALUES ('B0004', '农业银行');

-- ----------------------------
-- Table structure for customer
-- ----------------------------
DROP TABLE IF EXISTS `customer`;
CREATE TABLE `customer` (
  `c_id` char(6) NOT NULL,
  `name` varchar(30) NOT NULL,
  `location` varchar(30) DEFAULT NULL,
  `salary` double(8,2) DEFAULT NULL,
  PRIMARY KEY (`c_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of customer
-- ----------------------------
INSERT INTO `customer` VALUES ('101001', '孙杨', '广州', '1234.00');
INSERT INTO `customer` VALUES ('101002', '郭海', '南京', '3526.00');
INSERT INTO `customer` VALUES ('101003', '卢江', '苏州', '6892.00');
INSERT INTO `customer` VALUES ('101004', '郭惠', '济南', '3492.00');

-- ----------------------------
-- Table structure for deposite
-- ----------------------------
DROP TABLE IF EXISTS `deposite`;
CREATE TABLE `deposite` (
  `d_id` int(11) NOT NULL,
  `c_id` char(6) DEFAULT NULL,
  `b_id` char(5) DEFAULT NULL,
  `dep_date` date DEFAULT NULL,
  `dep_type` int(11) DEFAULT NULL,
  `amount` double(10,3) DEFAULT NULL,
  PRIMARY KEY (`d_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of deposite
-- ----------------------------
INSERT INTO `deposite` VALUES ('1', '101001', 'B0001', '2011-04-05', '3', '42526.000');
INSERT INTO `deposite` VALUES ('2', '101002', 'B0003', '2012-07-15', '5', '66500.000');
INSERT INTO `deposite` VALUES ('3', '101003', 'B0002', '2010-11-24', '1', '42366.000');
INSERT INTO `deposite` VALUES ('4', '101004', 'B0004', '2008-03-31', '1', '62362.000');
INSERT INTO `deposite` VALUES ('5', '101001', 'B0003', '2002-02-07', '3', '56346.000');
INSERT INTO `deposite` VALUES ('6', '101002', 'B0001', '2004-09-23', '3', '353626.000');
INSERT INTO `deposite` VALUES ('7', '101003', 'B0004', '2003-12-14', '5', '36236.000');
INSERT INTO `deposite` VALUES ('8', '101004', 'B0002', '2007-04-21', '5', '26267.000');
INSERT INTO `deposite` VALUES ('9', '101001', 'B0002', '2011-02-11', '1', '435456.000');
INSERT INTO `deposite` VALUES ('10', '101002', 'B0004', '2012-05-13', '1', '234626.000');
INSERT INTO `deposite` VALUES ('11', '101003', 'B0003', '2001-01-24', '5', '26243.000');
INSERT INTO `deposite` VALUES ('12', '101004', 'B0001', '2009-08-23', '3', '45671.000');

-- ----------------------------
-- View structure for answer01
-- ----------------------------
DROP VIEW IF EXISTS `answer01`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `answer01` AS select `b`.`b_id` AS `b_id`,`b`.`bank_name` AS `bank_name`,sum(`d`.`amount`) AS `total` from (`deposite` `d` join `bank` `b` on((`b`.`b_id` = `d`.`b_id`))) where (`d`.`b_id` = `b`.`b_id`) group by `b`.`bank_name` ;

-- ----------------------------
-- View structure for answer02
-- ----------------------------
DROP VIEW IF EXISTS `answer02`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `answer02` AS select `c`.`name` AS `客户姓名`,`b`.`bank_name` AS `银行姓名`,`d`.`amount` AS `存款金额` from ((`deposite` `d` join `customer` `c`) join `bank` `b`) where ((`b`.`b_id` = `d`.`b_id`) and (`d`.`c_id` = `c`.`c_id`) and (`c`.`location` in ('广州','苏州','济南')) and (`d`.`amount` between 300000 and 500000)) ;

-- ----------------------------
-- View structure for answer03
-- ----------------------------
DROP VIEW IF EXISTS `answer03`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `answer03` AS select `c`.`name` AS `客户姓名`,`b`.`bank_name` AS `银行名称`,`d`.`amount` AS `存款金额` from ((`deposite` `d` join `customer` `c`) join `bank` `b`) where ((`b`.`b_id` = `d`.`b_id`) and (`b`.`bank_name` = '农业银行') and (`d`.`c_id` = `c`.`c_id`)) limit 2 ;

-- ----------------------------
-- View structure for answer05
-- ----------------------------
DROP VIEW IF EXISTS `answer05`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `answer05` AS select `c`.`c_id` AS `客户id`,`c`.`name` AS `客户姓名`,`b`.`b_id` AS `银行标识`,`b`.`bank_name` AS `银行名称`,`d`.`amount` AS `存款金额` from ((`deposite` `d` join `customer` `c`) join `bank` `b`) where ((`b`.`b_id` = `d`.`b_id`) and (`d`.`c_id` = `c`.`c_id`) and (`d`.`dep_date` >= '2011-04-05')) order by `d`.`amount` ;

-- ----------------------------
-- View structure for answer06
-- ----------------------------
DROP VIEW IF EXISTS `answer06`;
CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `answer06` AS select `c`.`c_id` AS `客户id`,`c`.`name` AS `客户姓名`,`b`.`b_id` AS `银行标识`,`b`.`bank_name` AS `银行名称`,`d`.`dep_date` AS `存款日期`,`d`.`amount` AS `存款金额` from ((`deposite` `d` join `customer` `c`) join `bank` `b`) where ((`b`.`b_id` = `d`.`b_id`) and (`d`.`c_id` = `c`.`c_id`) and (`c`.`name` = '郭海') and (`b`.`bank_name` = '工商银行')) ;

-- ----------------------------
-- Procedure structure for answer07
-- ----------------------------
DROP PROCEDURE IF EXISTS `answer07`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` PROCEDURE `answer07`(
	in num INT
)
begin
	SELECT name 客户姓名,amount 金额,dep_type 存款期限 
	FROM deposite d,customer c,bank b 
	WHERE b.b_id=d.b_id AND d.c_id=c.c_id  
	AND bank_name='工商银行' AND amount>=num;
end
;;
DELIMITER ;

 

Guess you like

Origin blog.csdn.net/weixin_44893902/article/details/112500106