Create table and insert data
Field name Data type Primary key Foreign key Non-null Unique auto-increment
id INT Yes No Yes Yes No
name VARCHAR(50) No No Yes No No
glass VARCHAR(50) No No Yes No
sch 表内容
id name glass
1 xiaommg glass 1
2 xiaojun glass
1. Create a storage function that can count the number of records in the table. The function name is count_sch()
create function `count_sch`() returns int(11)
begin declare c int default 0; select count(1) into c from emp; return c; end
2. Create a stored procedure avg_sai with 3 parameters, namely deptno, job, receiving the average salary,
function query emp table dept is 30, job is the average salary of the salesperson.
create procedure `avg_sai`(in deptno int(10),in partment carchar(20),out avg_total float(20))
begin select avg(incoming) into avg_total from emp where dept=deptno and job=partment;
end