国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

頭歌實踐教學(xué)平臺數(shù)據(jù)庫原理與應(yīng)用實訓(xùn)答案

這篇具有很好參考價值的文章主要介紹了頭歌實踐教學(xué)平臺數(shù)據(jù)庫原理與應(yīng)用實訓(xùn)答案。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

目錄

實訓(xùn)一:數(shù)據(jù)定義和操縱(4課時)

初識MySQL數(shù)據(jù)庫

第1關(guān):創(chuàng)建數(shù)據(jù)庫

?第2關(guān):創(chuàng)建表

?第3關(guān):使用主鍵約束

第4關(guān):外鍵約束

第5關(guān):添加常用約束

DDL語言的使用

第1關(guān):創(chuàng)建數(shù)據(jù)庫

?第2關(guān):?創(chuàng)建表

?第3關(guān):添加字段

?第4關(guān):刪除字段

?第5關(guān):修改字段

?第6關(guān):添加唯一性約束

DML語言的使用

第1關(guān):insert...into方式插入數(shù)據(jù)

第2關(guān):更新數(shù)據(jù)

第3關(guān):更新數(shù)據(jù)-練習(xí)

第4關(guān):刪除數(shù)據(jù)

?第5關(guān):創(chuàng)建表-練習(xí)

?第6關(guān):刪除數(shù)據(jù)-練習(xí)1

第7關(guān):刪除數(shù)據(jù)-練習(xí)2

MySQL數(shù)據(jù)庫 - 數(shù)據(jù)更新

第1關(guān):插入數(shù)據(jù)

?第2關(guān):更新數(shù)據(jù)

?第3關(guān):刪除數(shù)據(jù)

?MySQL數(shù)據(jù)庫 - 數(shù)據(jù)庫和表的基本操作(一)

第1關(guān):查看表結(jié)構(gòu)與修改表名

?第2關(guān):修改字段名與字段數(shù)據(jù)類型

?第3關(guān):添加與刪除字段

第4關(guān):修改字段的排列位置

?第5關(guān):刪除表的外鍵約束

實訓(xùn)二:單表查詢(4課時)

單表查詢(一)student表查詢

第1關(guān):選擇列查詢

?第2關(guān):去除重復(fù)結(jié)果

第3關(guān):范圍查詢

?第4關(guān):帶IN關(guān)鍵字的查詢

?第5關(guān):匹配查詢

?第6關(guān):范圍查詢-練習(xí)

?第7關(guān):where子句查詢

單表查詢(二)基本查詢

第1關(guān):基本查詢語句

?第2關(guān):帶 IN 關(guān)鍵字的查詢

第3關(guān):帶 BETWEEN AND 的范圍查詢

?單表查詢(三)聚集函數(shù)

第1關(guān):COUNT( )函數(shù)

?第2關(guān):COUNT( )函數(shù)-練習(xí)

第3關(guān):AVG( )函數(shù)、MAX函數(shù)和MIN函數(shù)

?第4關(guān):分組查詢

?第5關(guān):倒序排列

單表查詢(四)-分組操作符與聚集函數(shù)?

第1關(guān):數(shù)據(jù)統(tǒng)計(初級)

第2關(guān):數(shù)據(jù)統(tǒng)計初級應(yīng)用

?第3關(guān):數(shù)據(jù)統(tǒng)計綜合應(yīng)用

?單表查詢(五)排序和分組

第1關(guān):對查詢結(jié)果進行排序

第2關(guān):分組查詢

第3關(guān):使用 LIMIT 限制查詢結(jié)果的數(shù)量

?單表查詢(六)綜合查詢

第1關(guān):基本查詢語句

第2關(guān):帶 IN 關(guān)鍵字的查詢

第3關(guān):帶 BETWEEN AND 的范圍查詢

?第4關(guān):帶 LIKE 的字符匹配查詢

第5關(guān):查詢空值與去除重復(fù)結(jié)果實訓(xùn)三:多表查詢(4課時)

?第6關(guān):帶 AND 與 OR 的多條件查詢

?第7關(guān):對查詢結(jié)果進行排序

?第8關(guān):分組查詢

?第9關(guān):使用 LIMIT 限制查詢結(jié)果的數(shù)量

實訓(xùn)三:多表查詢(4課時)

多表查詢-子查詢(一)

第1關(guān):子查詢

第2關(guān):子查詢-練習(xí)

?第3關(guān):子查詢-練習(xí)一

第4關(guān):子查詢-練習(xí)二

?第5關(guān):子查詢-練習(xí)三

?第6關(guān):子查詢-練習(xí)四

?多表查詢 - 子查詢(二)

第1關(guān):帶比較運算符的子查詢

?第2關(guān):關(guān)鍵字子查詢

多表查詢-連接查詢(一)

第1關(guān):自然連接

第2關(guān):等值連接

第3關(guān):JOIN連接

第4關(guān):自身連接查詢

第5關(guān):外部連接查詢

多表查詢- 連接查詢(二)

第1關(guān):內(nèi)連接查詢

第2關(guān):外連接查詢

第3關(guān):復(fù)合條件連接查詢

大學(xué)數(shù)據(jù)庫創(chuàng)建與查詢實戰(zhàn)

第1關(guān):數(shù)據(jù)庫表設(shè)計

第2關(guān):查詢(一)

第3關(guān):查詢(二)

第4關(guān):查詢(三)

第5關(guān):查詢(四)

第6關(guān):查詢(五)

實訓(xùn)四:索引與視圖(2課時)

MySQL開發(fā)技巧 - 索引第1關(guān):索引

?MySQL開發(fā)技巧 - 視圖

第1關(guān):視圖

?索引(teachingdb數(shù)據(jù)庫)

第1關(guān):索引

?第2關(guān):刪除索引-練習(xí)

?SQL視圖(teachingdb數(shù)據(jù)庫)

第1關(guān):創(chuàng)建視圖

第2關(guān):創(chuàng)建視圖-練習(xí)一

MySQL-索引和視圖

第1關(guān):建立索引

?第2關(guān):建立視圖并更新視圖

第3關(guān):建立基于多表的視圖?

實訓(xùn)五:數(shù)據(jù)庫安全控制(2課時)

創(chuàng)建用戶

第1關(guān):創(chuàng)建用戶

?第2關(guān):創(chuàng)建用戶-練習(xí)!!!

授權(quán)及回收權(quán)限

第1關(guān):授權(quán)

?第2關(guān):授權(quán)-練習(xí)一

第3關(guān):授權(quán)-練習(xí)二

第4關(guān):授權(quán)-練習(xí)三

?第5關(guān):回收權(quán)限

MySQL-安全性控制

第1關(guān):用戶和權(quán)限

第2關(guān):用戶、角色與權(quán)限

MySQL數(shù)據(jù)庫 - 授權(quán)與撤銷授權(quán)

第1關(guān):數(shù)據(jù)庫授權(quán)

第2關(guān):數(shù)據(jù)庫撤銷權(quán)限

實訓(xùn)六:數(shù)據(jù)完整性

實訓(xùn)七:存儲過程與觸發(fā)器(4課時)

存儲過程、函數(shù)與觸發(fā)器

第1關(guān):創(chuàng)建存儲過程

第2關(guān):創(chuàng)建函數(shù)-count_credit

第3關(guān):存儲過程-調(diào)用函數(shù)count_credit

第4關(guān):創(chuàng)建觸發(fā)器-計算總學(xué)分!!!

第5關(guān):創(chuàng)建觸發(fā)器-練習(xí)級聯(lián)刪除操作

存儲過程

第1關(guān):建立和調(diào)用存儲過程(不帶輸出參數(shù)的存儲過程)

第2關(guān):建立和調(diào)用存儲過程(帶輸出參數(shù))

第3關(guān):建立和調(diào)用存儲函數(shù)

第4關(guān):修改多個數(shù)據(jù)表的存儲過程

第5關(guān):使用游標的存儲過程文章來源地址http://www.zghlxwxcb.cn/news/detail-715935.html


實訓(xùn)一:數(shù)據(jù)定義和操縱(4課時)

初識MySQL數(shù)據(jù)庫

第1關(guān):創(chuàng)建數(shù)據(jù)庫

mysql -uroot -p123123 -h127.0.0.1
create database MyDb;
show databases;

?第2關(guān):創(chuàng)建表

mysql -uroot -p123123 -h127.0.0.1
create database TestDb;
 create table t_emp( id int, name varchar(32), deptId int , salary float);

?第3關(guān):使用主鍵約束

mysql -uroot -p123123 -h127.0.0.1


create database MyDb;


use MyDb;


create table t_user1(
userId INT PRIMARY KEY,
name VARCHAR(32),
password VARCHAR(11),
phone VARCHAR(11),
email VARCHAR(32));


create table t_user2(
name VARCHAR(32),
phone VARCHAR(11),
email VARCHAR(32),
PRIMARY KEY(name,phone));

第4關(guān):外鍵約束

mysql -uroot -p123123 -h127.0.0.1


create database MyDb;


use MyDb;



CREATE TABLE t_class
(
    id INT  PRIMARY KEY,
    name VARCHAR(22) 
);

CREATE TABLE t_student
(
    id INT  PRIMARY KEY,
    name VARCHAR(22) ,
    classId int,
    CONSTRAINT fk_stu_class1 FOREIGN KEY(classId) REFERENCES t_class(id)
);

第5關(guān):添加常用約束

mysql -uroot -p123123 -h127.0.0.1


CREATE DATABASE MyDb;



USE MyDb;


CREATE TABLE t_user
(
    id INT  PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(32) NOT NULL UNIQUE,
    sex VARCHAR(4) DEFAULT '男'
)DEFAULT CHARSET=utf8;

DDL語言的使用

第1關(guān):創(chuàng)建數(shù)據(jù)庫

  create database teachingdb;

?第2關(guān):?創(chuàng)建表

use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  create table student(
      sno char(5) primary key,
      sname varchar(20) NOT null,
      sdept varchar(20) not null,
      sclass char(2) not null,
      ssex char(1),
      birthday date,
      totalcredit decimal(4,1)
      );

  
 /**********End**********/

?第3關(guān):添加字段

use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  alter table student add nativeplace varchar(20);
  

--   alter table student add nativeplace varchar(20);
 /**********End**********/

?第4關(guān):刪除字段

use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  ALTER TABLE student DROP nativeplace;
  
 /**********End**********/

?第5關(guān):修改字段

use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
   ALTER TABLE student MODIFY ssex varchar(3);
  
 /**********End**********/

?第6關(guān):添加唯一性約束

use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
 alter table course add constraint uk_cno unique(cname); 
  
 /**********End**********/


DML語言的使用

第1關(guān):insert...into方式插入數(shù)據(jù)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  INSERT INTO student  VALUES (11111,'馬明','計算機','01','女','2000-01-02',null);
  
 /**********End**********/


第2關(guān):更新數(shù)據(jù)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
UPDATE student
SET totalcredit = 2.0
  
 /**********End**********/

-- update student set totalcredit=2.0;

第3關(guān):更新數(shù)據(jù)-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  UPDATE student 
  SET birthday = '2000-01-22'
  WHERE sname='馬小燕';  
  
 /**********End**********/

第4關(guān):刪除數(shù)據(jù)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
   DELETE FROM student WHERE sno = '11111';
  
 /**********End**********/


?第5關(guān):創(chuàng)建表-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
-- select * from  student ;


create table s1 as select * from student;
 /**********End**********/


?第6關(guān):刪除數(shù)據(jù)-練習(xí)1

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
  DELETE FROM  s1 WHERE sdept='計算機';
 /**********End**********/


第7關(guān):刪除數(shù)據(jù)-練習(xí)2

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
drop table s1 ;

  
 /**********End**********/


MySQL數(shù)據(jù)庫 - 數(shù)據(jù)更新

第1關(guān):插入數(shù)據(jù)

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## bundle insert the value #########
INSERT INTO tb_emp(Id,Name,DeptId,Salary) 
VALUES (1,"Nancy",301,2300.00),
(2,"Tod",303,5600.00),(3,"Carly",301,3200.00);

########## End ##########
SELECT * FROM tb_emp;
########## End ##########

?第2關(guān):更新數(shù)據(jù)

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## update the value ##########
UPDATE tb_emp
SET Name="Tracy",DeptId=302,Salary=4300.00
WHERE id=3;


########## End ##########

SELECT * FROM tb_emp;

########## End ##########

?第3關(guān):刪除數(shù)據(jù)

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## delete the value ##########
DELETE FROM tb_emp
WHERE Salary>3000;


########## End ##########

SELECT * FROM tb_emp;

########## End ##########

?MySQL數(shù)據(jù)庫 - 數(shù)據(jù)庫和表的基本操作(一)

第1關(guān):查看表結(jié)構(gòu)與修改表名

USE Company;

########## Begin ##########

########## modify the table name ##########
ALTER table tb_emp RENAME jd_emp;


########## show tables in this database ##########
show tables;


########## describe the table ##########
describe jd_emp;


########## End ##########

?第2關(guān):修改字段名與字段數(shù)據(jù)類型

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## change the column name ##########
ALTER TABLE tb_emp change Id prod_id int(11);


########## change the data type of column ##########
ALTER TABLE tb_emp MODIFY Name varchar(30);


########## End ##########

DESCRIBE tb_emp;

?第3關(guān):添加與刪除字段

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## add the column ##########
ALTER TABLE tb_emp ADD Country varchar(20) AFTER Name; 
########## delete the column ##########
ALTER TABLE tb_emp DROP Salary;


########## End ##########

DESCRIBE tb_emp;

第4關(guān):修改字段的排列位置

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## modify the column to top ##########
ALTER TABLE tb_emp MODIFY Name varchar(25) FIRST;


########## modify the column to the rear of another column ##########
ALTER TABLE tb_emp MODIFY DeptId int(11) AFTER Salary;


########## End ##########

DESCRIBE tb_emp;

?第5關(guān):刪除表的外鍵約束

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## delete the foreign key ##########
ALTER TABLE tb_emp DROP FOREIGN KEY emp_dept;


########## End ##########
SHOW CREATE TABLE tb_emp \G;

實訓(xùn)二:單表查詢(4課時)

單表查詢(一)student表查詢

第1關(guān):選擇列查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/

  select sno 學(xué)號, sname 姓名 from student where birthday >= "2000.1.1" and birthday <= "2000.12.31";
  
 /**********End**********/

?第2關(guān):去除重復(fù)結(jié)果

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  SELECT DISTINCT sno
FROM score ;
  
 /**********End**********/

第3關(guān):范圍查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
  SELECT *
FROM course 
WHERE ctime BETWEEN 1 AND 50;

 /**********End**********/

?第4關(guān):帶IN關(guān)鍵字的查詢


 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  SELECT *
  from student
  where sdept!='計算機' and sdept!='信息';
  
 /**********End**********/

?第5關(guān):匹配查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select *
  from student
  where sname like '%馬__';
  
 /**********End**********/

?第6關(guān):范圍查詢-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select *
  from score
  where tno='052501'and grade>='80' and grade<='90' and sno like '96%';
  
 /**********End**********/

?第7關(guān):where子句查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
    select sno, cno from score where grade is null;
 /**********End**********/

單表查詢(二)基本查詢

第1關(guān):基本查詢語句

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary ##########
select Name,Salary from tb_emp;

########## retrieving all the table ##########
select * from tb_emp;

########## End ##########

?第2關(guān):帶 IN 關(guān)鍵字的查詢

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary with IN statement ##########
SELECT Name,Salary FROM tb_emp WHERE Id !='1';


########## End ##########

第3關(guān):帶 BETWEEN AND 的范圍查詢

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary with BETWEEN AND statement ##########
SELECT Name,Salary FROM tb_emp 
WHERE Salary BETWEEN 3000 AND 5000;


########## End ##########

?單表查詢(三)聚集函數(shù)

第1關(guān):COUNT( )函數(shù)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select count(*) from student;
  
 /**********End**********/


?第2關(guān):COUNT( )函數(shù)-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
  select count(distinct sno)  from score;
 /**********End**********/


第3關(guān):AVG( )函數(shù)、MAX函數(shù)和MIN函數(shù)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select cno,AVG(grade),MAX(grade),MIN(grade) from score group by(cno);
 /**********End**********/


?第4關(guān):分組查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select sdept,count(*) from student group by sdept having count(*)<3;
  
 /**********End**********/

?第5關(guān):倒序排列

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select sdept,sclass,COUNT(*) from student group by sdept,sclass order by count(*) desc,sdept desc;
 /**********End**********/

單表查詢(四)-分組操作符與聚集函數(shù)?

第1關(guān):數(shù)據(jù)統(tǒng)計(初級)

USE test_wyy_db_guet
GO

SET NOCOUNT ON

 
-- ********** Begin ********** --
-- ********** 此處寫第一題的SQL語句 ********** --

select count(*) from course where credit>2;
-- ********** End ********** --

GO
 
-- ********** Begin ********** --
-- ********** 此處寫第二題的SQL語句 ********** --
select sum(credit) from course where cno like "BT%";
-- ********** End ********** --

GO

 
-- ********** Begin ********** --
-- ********** 此處寫第三題的SQL語句 ********** --
select left(cno,2),count(*)from course group by left(cno,2);
-- ********** End ********** --

GO

第2關(guān):數(shù)據(jù)統(tǒng)計初級應(yīng)用

USE test_wyy_db_guet
Go

SET NOCOUNT ON


-- ********** Begin ********** --
---------- 第一題----------
select count(model) from printer where color = "T" and type = "laser"; 
-- ********** End ********** --
GO


-- ********** Begin ********** --
---------- 第二題----------
select min(price) from printer;
-- ********** End ********** --
GO

-- ********** Begin ********** --
---------- 第三題----------
select model,price from printer where price >=(select max(price) from printer);
-- ********** End ********** --
GO

?第3關(guān):數(shù)據(jù)統(tǒng)計綜合應(yīng)用

USE test_wyy_db_guet
Go

SET NOCOUNT ON

---------- 第1題 ----------
-- ********** Begin ********** --
select hd from V_test group by hd having count(*) <3;


-- ********** End ********** --

GO

---------- 第2題 ----------
-- ********** Begin ********** --
select max(AvgSpeed) from
(select maker maker,Avg(speed) AvgSpeed
 from V_test 
 group by maker
 )name;


-- ********** End ********** --

GO

---------- 第3題 ----------
-- ********** Begin ********** --
select maker,count(*) from V_test where price>1000 group by maker;

-- ********** End ********** --

GO
---------- 第4題 ----------
-- ********** Begin ********** --
select maker,type,AVG(price) from V_test group by maker,type;



-- ********** End ********** --

GO

?單表查詢(五)排序和分組

第1關(guān):對查詢結(jié)果進行排序

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 查詢1班同學(xué)的所有信息以成績降序的方式顯示結(jié)果 ##########
select * from tb_score where class_id = 1 order by score desc;

########## End ##########

第2關(guān):分組查詢

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 對班級名稱進行分組查詢 ##########
SELECT * FROM tb_class GROUP BY class_id;

########## End ##########

第3關(guān):使用 LIMIT 限制查詢結(jié)果的數(shù)量

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 查詢班級中第2名到第5名的學(xué)生信息 ##########
SELECT * FROM tb_score order by score desc LIMIT 1,4;

########## End ##########

?單表查詢(六)綜合查詢

第1關(guān):基本查詢語句

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary ##########
select Name,Salary from tb_emp;

########## retrieving all the table ##########
select * from tb_emp;

########## End ##########

第2關(guān):帶 IN 關(guān)鍵字的查詢

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary with IN statement ##########
SELECT Name,Salary FROM tb_emp WHERE Id NOT IN (1);


########## End ##########

第3關(guān):帶 BETWEEN AND 的范圍查詢

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## retrieving the Name and Salary with BETWEEN AND statement ##########
SELECT Name,Salary FROM tb_emp 
WHERE Salary BETWEEN 3000 AND 5000;


########## End ##########

?第4關(guān):帶 LIKE 的字符匹配查詢

USE Company;

######### Begin #########
SELECT Name,Salary FROM tb_emp WHERE Name LIKE "C%";

######### End #########


第5關(guān):查詢空值與去除重復(fù)結(jié)果實訓(xùn)三:多表查詢(4課時)

USE Company;

######### Begin #########
SELECT * FROM tb_emp WHERE DeptId IS NULL;

######### End #########

######### Begin #########
SELECT DISTINCT Name FROM tb_emp;

######### End #########


?第6關(guān):帶 AND 與 OR 的多條件查詢

USE Company;

######### Begin #########
SELECT * FROM tb_emp WHERE DeptId=301 AND Salary > 3000;

######### End #########

######### Begin #########
SELECT * FROM tb_emp WHERE DeptId=301 OR DeptId=303;

######### End #########

?第7關(guān):對查詢結(jié)果進行排序

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 查詢1班同學(xué)的所有信息以成績降序的方式顯示結(jié)果 ##########
select * from tb_score where class_id = 1 order by score desc;

########## End ##########

?第8關(guān):分組查詢

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 對班級名稱進行分組查詢 ##########
SELECT * FROM tb_class GROUP BY class_id;

########## End ##########

?第9關(guān):使用 LIMIT 限制查詢結(jié)果的數(shù)量

USE School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########

########## 查詢班級中第2名到第5名的學(xué)生信息 ##########
SELECT * FROM tb_score order by score desc LIMIT 1,4;

########## End ##########

實訓(xùn)三:多表查詢(4課時)

多表查詢-子查詢(一)

第1關(guān):子查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/

    select sname, birthday from student where birthday < (select birthday from student where sname = "劉東明");
 /**********End**********/

第2關(guān):子查詢-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select student.sno,student.sname from student left join score on student.sno=score.sno where score.sno is null;
  
 /**********End**********/


?第3關(guān):子查詢-練習(xí)一

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select sname,sdept,birthday from student where birthday < any(select birthday from student where sdept="數(shù)學(xué)") and sdept <> "數(shù)學(xué)";
  
 /**********End**********/

第4關(guān):子查詢-練習(xí)二

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select student.sname,student.sdept from student,score where student.sno=score.sno and score.cno="004";
  
 /**********End**********/

?第5關(guān):子查詢-練習(xí)三

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select score.sno from score where cno in (select score.cno from score,student where student.sno=score.sno and student.sname='劉東明') and score.sno not in(select student.sno from student where student.sname='劉東明') group by sno having count(cno) >=(select count(cno) from score,student where score.sno=student.sno and student.sname='劉東明')  
 /**********End**********/


?第6關(guān):子查詢-練習(xí)四

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select distinct score.sno from score group by sno having count(cno) >=(select count(cno) from course);  
 /**********End**********/

?多表查詢 - 子查詢(二)

第1關(guān):帶比較運算符的子查詢

USE Company;

#請在此處添加實現(xiàn)代碼
########## Begin ##########
#1.查詢大于所有平均年齡的員工姓名與年齡
   select  name, age from tb_emp where age > (select avg(age) from tb_emp );

?第2關(guān):關(guān)鍵字子查詢

USE Company;
#請在此處添加實現(xiàn)代碼
########## Begin ##########

#1.使用 ALL 關(guān)鍵字進行查詢
select position,salary from tb_salary where salary >(select max(salary) from tb_salary where position="Java");
#2.使用 ANY 關(guān)鍵字進行查詢
select position,salary from tb_salary where salary >(select min(salary) from tb_salary where position="Java");
#3.使用 IN 關(guān)鍵字進行查詢
select position,salary from tb_salary where position="Java";
########## End ##########

多表查詢-連接查詢(一)

第1關(guān):自然連接

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
select student.sname,course.cname,teach.tname,score.grade from student,score,course,teach where student.sno=score.sno and score.tno=teach.tno and score.cno=course.cno and teach.tname="嚴敏" and course.cname="數(shù)學(xué)分析";
 /**********End**********/


第2關(guān):等值連接

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select student.sname,course.cname,teach.tname,score.grade from student,score,course,teach where student.sno=score.sno and score.tno=teach.tno and score.cno=course.cno and teach.tname="嚴敏" and course.cname="數(shù)學(xué)分析";
  
 /**********End**********/


第3關(guān):JOIN連接

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
  select student.sname,course.cname,teach.tname,score.grade from student,score,course,teach where student.sno=score.sno and score.tno=teach.tno and score.cno=course.cno and teach.tname="嚴敏" and course.cname="數(shù)學(xué)分析";
 /**********End**********/


第4關(guān):自身連接查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select s2.sname,s2.birthday from student s1,student s2 where s1.sname="劉東明" and s1.birthday>s2.birthday;
  
 /**********End**********/


第5關(guān):外部連接查詢

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  select student.sno,student.sname  from student left join score on student.sno=score.sno where score.sno is null; 
  
 /**********End**********/


多表查詢- 連接查詢(二)

第1關(guān):內(nèi)連接查詢

USE School;

########## 查詢數(shù)據(jù)表中學(xué)生姓名和對應(yīng)的班級 ##########
#請在此處添加實現(xiàn)代碼
########## Begin ##########
select tb_student.name studentName,tb_class.name className from tb_student,tb_class where tb_student.class_id=tb_class.id 



########## End ##########

第2關(guān):外連接查詢

USE School;

########## 使用左外連接查詢所有學(xué)生姓名和對應(yīng)的班級 ##########

#請在此處添加實現(xiàn)代碼
########## Begin ##########
select s1.name studentName,s2.name className from tb_student s1 left join tb_class
 s2 on s1.class_id=s2.id;


########## End ##########

########## 使用右外連接查詢所有學(xué)生姓名和對應(yīng)的班級 ##########

#請在此處添加實現(xiàn)代碼
########## Begin ##########
select s1.name studentName,s2.name className from tb_student s1 right join tb_class
 s2 on s1.class_id=s2.id; 



########## End ##########

第3關(guān):復(fù)合條件連接查詢

USE School;

########## 查詢所有班級里分數(shù)在90分以上的學(xué)生的姓名和學(xué)生的成績以及學(xué)生所在的班級 ##########
#請在此處添加實現(xiàn)代碼
########## Begin ##########
select tb_student.name studentName,tb_student.score,tb_class.name className from tb_student,tb_class where tb_student.class_id=tb_class.id and score>90;



########## End ##########

大學(xué)數(shù)據(jù)庫創(chuàng)建與查詢實戰(zhàn)

第1關(guān):數(shù)據(jù)庫表設(shè)計


use universityDB;
create table instructor(
    ID varchar(5) ,primary key(ID),
    name varchar(20) NOT NULL,
    dept_name varchar(20) DEFAULT NULL ,
    salary numeric(8,2)  check(salary>29000),
    foreign key (dept_name) references department(dept_name)
        on delete set null
);
create table section(
    course_id varchar(8)  ,
    sec_id varchar(8) ,
    semester varchar(6)  check(semester in('Fall','Winter','Spring','Summer')),
    year numeric(4,0)  ,
    building varchar(15)  ,
    room_number varchar(7)   ,
    time_slot_id varchar(4) ,
    primary key (course_id, sec_id, semester, year),
     foreign key (course_id) references course(course_id)
        on delete cascade,
     foreign key (building, room_number) references classroom(building, room_number)
);

########## End ##########

第2關(guān):查詢(一)

#********* Begin *********#
echo "
select name
from student where dept_name='Biology';
 
select name from instructor where salary> any(select salary 
from instructor where dept_name='Biology');
 
select name,department.dept_name,building 
from instructor ,department where instructor.dept_name=department.dept_name;
 
select distinct instructor.dept_name
from instructor,department where instructor.dept_name=department.dept_name and building='Watson';
 


"
#********* End *********#

第3關(guān):查詢(二)

#********* Begin *********#
echo "
select count(distinct ID) from teaches where semester ='spring' and year='2010';

select instructor.ID,name,dept_name from teaches,instructor where semester='Fall'and year='2009' and teaches.ID=instructor.ID group by ID having count(distinct course_id)=2;
select dept_name, count(distinct instructor.ID) as instr_count from instructor,teaches where semester='Spring' and year='2010' and instructor.ID=teaches.ID group by dept_name having count(distinct course_id)>=1
"
#********* End *********#

第4關(guān):查詢(三)

#********* Begin *********#
echo "
select instructor.* from instructor order by salary desc,name asc ;
select max(salary) from instructor;
select dept_name from instructor group by dept_name having avg(salary)=(
select max(avgs) from(select avg(salary) avgs,dept_name  from instructor group by dept_name) a);
select dept_name, avg(salary) as avg_salary from instructor group by dept_name having avg(salary)>50000  order by dept_name asc,avg(salary) desc;
"
#********* End *********#

第5關(guān):查詢(四)

#********* Begin *********#
echo "
select distinct course_id 
from section 
where semester='Fall' and year=2009 and
course_id not in (select course_id from section where semester='Spring' and
year=2010);
 
select course_id 
from section as S 
where year=2009 and semester='Fall' and exists
(select section.* from section as T where year=2010 and semester='Spring' and
S.course_id=T.course_id);
 
select course_id 
from section 
where year=2009 and semester='Fall' union all select
course_id from section where year=2010 and semester='Spring';
 
select course_id,semester,year,sec_id,avg(tot_cred) 
from takes join student join department on takes.ID = student.ID 
where year=2009 group by course_id,semester,year,sec_id having count(takes.ID)>=13;
 
 
"

#********* End *********#

第6關(guān):查詢(五)

#********* Begin *********#
echo "
select instructor.name,teaches.course_id 
from instructor,teaches 
where instructor.ID=teaches.ID and dept_name='Physics';
 
select name 
from instructor 
where dept_name='Physics' and salary>80000;
update instructor set salary = case when salary <= 100000 then salary*1.05 else salary*1.03 end;
create view Physics_fall_2009 as select course.course_id,building,room_number from course,section where course.course_id = section.course_id and course.dept_name='Physics' and section.semester='Fall' and section.year='2009';
 
 
"

#********* End *********#

實訓(xùn)四:索引與視圖(2課時)

MySQL開發(fā)技巧 - 索引
第1關(guān):索引

use School;
#請在此處添加實現(xiàn)代碼
########## Begin ##########

#1.創(chuàng)建名為pk_student的主鍵索引
create table student(
    stu_id int not null,
    name varchar(25) not null,
    age int not null,
    sex char(2) not null,
    classes int not null,
    grade int not null,
    primary key(stu_id) 
);

#2.創(chuàng)建名為idx_age的普通索引
create index idx_age on student(age);

#3.創(chuàng)建名為uniq_classes的唯一索引
create unique index uniq_classes on student(classes);

#4.創(chuàng)建名為idx_group的組合索引
create index idx_group on student(name,sex,grade);

########## End ##########

?MySQL開發(fā)技巧 - 視圖

第1關(guān):視圖

use School;

#請在此處添加實現(xiàn)代碼
########## Begin ##########
create view stu_view as select math,chinese,math+chinese from student;

#1.創(chuàng)建單表視圖
create view stu_classes as select student.stu_id,name,classes from student,stu_info where student.stu_id=stu_info.stu_id;

#2.創(chuàng)建多表視圖


########## End ##########

?索引(teachingdb數(shù)據(jù)庫)

第1關(guān):索引

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  
  create index idx_sname on student(sname);
 /**********End**********/

?第2關(guān):刪除索引-練習(xí)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  drop index idx_sname;
  
 /**********End**********/

?SQL視圖(teachingdb數(shù)據(jù)庫)

第1關(guān):創(chuàng)建視圖

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  create view student_cs as select * from student where sdept="計算機";

  
 /**********End**********/

第2關(guān):創(chuàng)建視圖-練習(xí)一

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
 create view v_grade_avg as select sno 學(xué)號,
 avg(grade) 平均成績 from score
 group by sno;

  
 /**********End**********/


MySQL-索引和視圖

第1關(guān):建立索引

 use province;
 #代碼開始
alter table jdxx add primary key zsy(sf,cs,qx,name);
create index namesy on jdxx(name);
 
 #代碼結(jié)束
 show index in jdxx\g;

?第2關(guān):建立視圖并更新視圖

use province;
#代碼開始
create view csxx as select qx,name from jdxx where qx in('天心區(qū)','寧鄉(xiāng)縣','岳麓區(qū)','開福區(qū)','望城縣','瀏陽市','芙蓉區(qū)','長沙縣','雨花區(qū)');
update csxx set name="月湖街道" where name="西湖街道" and qx='開福區(qū)';
#代碼結(jié)束
select * from csxx;

第3關(guān):建立基于多表的視圖?

use province
 #代碼開始
 

create view csbm as select jdxx.qx,jdxx.name,qxyzbm.qxbm from jdxx,qxyzbm where jdxx.qx=qxyzbm.qx and jdxx.cs='長沙市';
 #代碼結(jié)束
 select * from csbm;

實訓(xùn)五:數(shù)據(jù)庫安全控制(2課時)

創(chuàng)建用戶

第1關(guān):創(chuàng)建用戶

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  create user user1 @localhost identified by 'user1';
 

  
 /**********End**********/


?第2關(guān):創(chuàng)建用戶-練習(xí)!!!

 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
   
   create user user2 identified by 'user2';
 /**********End**********/

授權(quán)及回收權(quán)限

第1關(guān):授權(quán)

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/

GRANT USAGE ON *.* TO 'user1'@'localhost' ;
GRANT ALL PRIVILEGES ON `teachingdb2`.* TO 'user1'@'localhost';
  
 /**********End**********/

?第2關(guān):授權(quán)-練習(xí)一

 use teachingdb;

 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
 grant select on teachingdb.* to user1@localhost with grant option; 
  
 /**********End**********/

第3關(guān):授權(quán)-練習(xí)二

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
    #grant all on teachingdb to user1@localhost, user2@localhost;
    grant all on student to user1@localhost, user2@localhost;
  
  
 /**********End**********/

第4關(guān):授權(quán)-練習(xí)三

 use teachingdb;
 
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/

    #grant update(grade) on score to user2@localhost;
  
  
 /**********End**********/

?第5關(guān):回收權(quán)限

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  revoke select on teachingdb.* from user1@localhost;
  
 /**********End**********/

MySQL-安全性控制

第1關(guān):用戶和權(quán)限

# 請?zhí)顚懻Z句,完成以下功能:
#(1) 創(chuàng)建用戶tom和jerry,初始密碼均為'123456';
create user tom identified by '123456';
create user jerry identified by '123456';
#(2) 授予用戶tom查詢客戶的姓名,郵箱和電話的權(quán)限,且tom可轉(zhuǎn)授權(quán)限;grant 權(quán)限[,權(quán)限] ... on 數(shù)據(jù)庫對象 to user|role,[user|role]... [with grant option]
grant select(c_name,c_mail,c_phone) on client to tom with grant option;
#(3) 授予用戶jerry修改銀行卡余額的權(quán)限;
grant update(b_balance) on bank_card to jerry;
#(4) 收回用戶Cindy查詢銀行卡信息的權(quán)限。
revoke select on bank_card from Cindy;

#revoke 權(quán)限[,權(quán)限]... on 數(shù)據(jù)庫對象 from user|role[,user|role]... 

第2關(guān):用戶、角色與權(quán)限

# 請?zhí)顚懻Z句,完成以下功能:
# (1) 創(chuàng)建角色client_manager和fund_manager;
create role client_manager,fund_manager;
# (2) 授予client_manager對client表擁有select,insert,update的權(quán)限;
grant select,insert,update on client to client_manager;   
# (3) 授予client_manager對bank_card表擁有查詢除銀行卡余額外的select權(quán)限;
grant select(b_number,b_type,b_c_id)on bank_card to client_manager;
# (4) 授予fund_manager對fund表的select,insert,update權(quán)限;
grant select,insert,update on fund to fund_manager;
# (5) 將client_manager的權(quán)限授予用戶tom和jerry;
grant client_manager to tom,jerry;
# (6) 將fund_manager權(quán)限授予用戶Cindy.
grant fund_manager to Cindy;

MySQL數(shù)據(jù)庫 - 授權(quán)與撤銷授權(quán)

第1關(guān):數(shù)據(jù)庫授權(quán)


##########  開始編寫 SQL  ##########


##########  開始編寫 SQL  ##########
-- set password for casual_user@localhost=password('123456');
-- grant select,insert,update on *.* to
-- casual_user@localhost identified by'123456';

-- grant select,insert,update  on *.* to casual_user@'localhost' identified by "123123";


set password for casual_user@'localhost' = Password('123456');

grant select,insert,update on *.* to casual_user@'localhost' identified by "123456";

第2關(guān):數(shù)據(jù)庫撤銷權(quán)限

##########  開始編寫 SQL  ##########
-- revoke all
-- on mydb1.table1
-- from 'user1'@'localhost';

-- revoke all
-- on mydb1.table2
-- from 'user1'@'localhost';

-- revoke insert,select,update,create,delete,alter
-- on mydb2.*
-- from 'user2'@'localhost';



-- revoke all on mydb1.table1 from 'user1'@'ip';
revoke all on mydb1.table1 from user1@'localhost';
revoke all on mydb1.table2 from user1@'localhost';
revoke select,update,insert,create,delete,alter on mydb2.* from user2@'localhost';

實訓(xùn)六:數(shù)據(jù)完整性

實訓(xùn)七:存儲過程與觸發(fā)器(4課時)

存儲過程、函數(shù)與觸發(fā)器

第1關(guān):創(chuàng)建存儲過程

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  delimiter $$
  create procedure pro_findname(in name char(3))
  Begin
  select * from student where sname like concat ('%',name,'%');
  End
  $$
  delimiter ;
  
 /**********End**********/


第2關(guān):創(chuàng)建函數(shù)-count_credit

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
delimiter $
create function count_credit(psno char(10)) returns int

Begin
declare xx int;
select sum(credit) from course where cno in(
  select cno from score where grade >=60 and sno=psno
) into xx;
return xx;

end$

delimiter ;
 /**********End**********/


第3關(guān):存儲過程-調(diào)用函數(shù)count_credit

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
   delimiter //
   create procedure p_count_credit()
   Begin
   declare flag boolean default true;
   declare psno char(5);
   declare stu_cur cursor for select sno from student;
   declare continue handler for not found set flag=false;
   open stu_cur;
   while flag do
   fetch stu_cur into psno;
   update student set totalcredit=count_credit(psno) where sno=psno;
   end while;
   close stu_cur;
   end //
  delimiter ;
 /**********End**********/


第4關(guān):創(chuàng)建觸發(fā)器-計算總學(xué)分!!!

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  delimiter $$
  drop trigger if exists sum_credit$$
  create trigger sum_credit after insert on score
  for each row
  Begin
  update student set totalcredit=totalcredit
  (select credit from course where cno=new.cno)
  where sno=new.sno and new.grade>=60;
  end $$
  delimiter ;
 /**********End**********/


第5關(guān):創(chuàng)建觸發(fā)器-練習(xí)級聯(lián)刪除操作

 use teachingdb;
 /****請在此編寫代碼,操作完畢之后點擊評測******/
 
 /**********Begin**********/
  delimiter $$
  drop trigger if exists del_student_score$$
  create trigger del_student_score before delete
  on student
  for each row
  Begin
  delete from score where sno=old.sno;
  end$$
  delimiter ;
  
 /**********End**********/


存儲過程

第1關(guān):建立和調(diào)用存儲過程(不帶輸出參數(shù)的存儲過程)

 use province;
 #代碼開始
 #定義過程

 #調(diào)用過程

use province;
#代碼開始
delimiter $$
create procedure dqxx(in city varchar(10),in district varchar(10)) 
begin 
    declare x int;
    declare jd int;
    declare z int;
    declare qt int;
    select count(name) from jdxx where cs = city and qxmc = district and name like "%鄉(xiāng)" into x;
    select count(name) from jdxx where cs = city and qxmc = district and name like "%街道" into jd;
    select count(name) from jdxx where cs = city and qxmc = district and name like "%鎮(zhèn)" into z;
    select count(name) from jdxx where cs = city and qxmc = district and name not like "%鎮(zhèn)" and name not like "%街道" and name not like "%鄉(xiāng)" into qt;
    select x 鄉(xiāng), jd 街道, z 鎮(zhèn), qt 其他;
end $$
delimiter ;
call dqxx("長沙市", "開福區(qū)");
call dqxx("廈門市", "同安區(qū)");
#代碼結(jié)束

 #代碼結(jié)束

第2關(guān):建立和調(diào)用存儲過程(帶輸出參數(shù))

 use sale;
 #代碼開始
 #定義過程

 #調(diào)用過程
use sale;
#代碼開始
delimiter $$
create procedure ygyj(in nf int, in yf int, in xm varchar(10), out pj varchar(10))
begin
    declare jg int;
    select sum(sjfk) from xsd join gzry on gzry.gyh = xsd.gyh where year(xsrq) = nf and month(xsrq) = yf and gyxm = xm into jg;
    case
        when isnull(jg) then set pj = "無業(yè)績";
        when jg < 5000 then set pj = "不達標";
        when jg < 10000 then set pj = "達標";
        else set pj = "優(yōu)秀";
    end case;
end $$
delimiter ;
call ygyj(2015, 7, "王雅靜", @yj1);
call ygyj(2015, 6, "廖秉嫻", @yj2);
call ygyj(2015, 7, "趙敏", @yj3);
call ygyj(2015, 7, "章偉", @yj4);
#代碼結(jié)束
select @yj1,@yj2,@yj3,@yj4;

第3關(guān):建立和調(diào)用存儲函數(shù)

use sale;
#代碼開始
#函數(shù)定義
#調(diào)用函數(shù)
use sale;
#代碼開始
delimiter $$
create function gkjb(nf int, xm varchar(10))
    returns varchar(10)
DETERMINISTIC
begin
    declare jg int;
    declare pj varchar(10);
    select sum(sjfk)
    from xsd join gk on gk.hyh = xsd.hyh 
    where name = xm and year(xsrq) = nf into jg;
        case
        when isnull(jg) then
        set pj = "非會員";
        when jg < 5000 then
        set pj = "一般會員";
        when jg < 10000 then
        set pj = "vip";
        else set pj = "超級vip";
        end case;
    return pj;
end $$
delimiter ;
select name 姓名, gkjb(2015, name) 等級 from gk;
#代碼結(jié)束

第4關(guān):修改多個數(shù)據(jù)表的存儲過程

 use library;
 #代碼開始
 #定義過程
 #調(diào)用過程
use library;
#代碼開始
delimiter $$
create procedure hs(in sh varchar(8), in dzbh varchar(3), in rq date, out zt varchar(12))
begin
    declare jywh int;
    select count(*) from borrow where txm=sh and dzzh=dzbh and isnull(hsrq) into jywh;
    if jywh=0 then
        set zt = "沒有該借閱";
    else
        update borrow set hsrq=rq where dzzh=dzbh and txm=sh and isnull(hsrq);
        update book set zk=1 where txm=sh;
        set zt = "還書成功";
    end if;
end $$
delimiter ;
call hs("P0000001", "001", "2022-5-1", @zt1);
call hs("P0000001", "002", "2022-5-1", @zt2);
#代碼結(jié)束
select @zt1,@zt2;
select txm, sm, zk from book;
select * from borrow;

第5關(guān):使用游標的存儲過程

 use province;
 #代碼開始


use province;
#代碼開始
delimiter $$
create procedure tjdq(in sm varchar(10))
begin
    declare flag int default 1;
    declare city varchar(10);
    declare qx varchar(10);
    declare jd int;
    declare x int;
    declare z int;
    declare qt int;
    declare dq cursor for select distinct cs, qxmc from jdxx where sf = sm;
    declare continue handler for not found set flag = 0;
    delete from dqtj;
    open dq;
        fetch dq into city, qx;
        while flag = 1 do
            select count(*) from jdxx where cs = city and qxmc = qx and name like "%街道" into jd;
            select count(*) from jdxx where cs = city and qxmc = qx and name like "%鄉(xiāng)" into x;
            select count(*) from jdxx where cs = city and qxmc = qx and name like "%鎮(zhèn)" into z;
            select count(*) from jdxx where cs = city and qxmc = qx and name not like "%鎮(zhèn)" and name not like "%街道" and name not like "%鄉(xiāng)" into qt;
            insert into dqtj values(city, qx, x, jd, z, qt);
            fetch dq into city, qx;
        end while;
    close dq;
end $$
delimiter ;
call tjdq("安徽省");
#代碼結(jié)束
select * from dqtj;

到了這里,關(guān)于頭歌實踐教學(xué)平臺數(shù)據(jù)庫原理與應(yīng)用實訓(xùn)答案的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 頭歌實踐教學(xué)平臺答案(消息隊列面試題及答案)

    頭歌實踐教學(xué)平臺消息隊列 面試題及答案,消息隊列?試題及答案。 1、為什么使用消息隊列? 消息隊列使用的場景和中間件有很多,但解決的核心問題主要是:異步、解耦、消峰填谷。 異步、解耦、消峰填谷這是消息隊列最大的優(yōu)點,除了這些消息隊列還可以會解決一些

    2024年02月11日
    瀏覽(22)
  • 頭歌實踐教學(xué)平臺答案(Python實訓(xùn)答案之循環(huán)結(jié)構(gòu))

    頭歌實踐教學(xué)平臺答案(Python實訓(xùn)答案之循環(huán)結(jié)構(gòu)),一共有6關(guān), Python實訓(xùn)答案編程要求 本關(guān)的編程任務(wù)是補全line.py文件中的判斷語句部分,具體要求如下: 填入當(dāng)已處理零件數(shù)小于總零件數(shù)count partcount時的while循環(huán)判斷語句; 在停電時填入break語句跳出循環(huán)。 本關(guān)涉及的代

    2024年04月13日
    瀏覽(132)
  • python頭歌實踐教學(xué)平臺-python第三章作業(yè)(初級)

    第1關(guān)?判斷是否直角三角形 第2關(guān)?今年多少天? 第3關(guān)?判斷三角形并計算面積 第4關(guān)?身高測算 第5關(guān)?個稅計算器 第6關(guān)?判斷閏年 第7關(guān)?分段函數(shù)B 第8關(guān)?百分制成績轉(zhuǎn)換五分制E 第9關(guān)?正負交錯數(shù)列前n項和 第10關(guān)?求數(shù)列前n項的平方和 第11關(guān)?百錢買百雞A 第12關(guān)?用戶登錄

    2024年02月02日
    瀏覽(176)
  • 頭歌實踐教學(xué)平臺Python-Python第二章作業(yè)(初級)

    頭歌實踐教學(xué)平臺Python-Python第二章作業(yè)(初級)

    第1關(guān):三角形周長及面積 任務(wù)描述 輸入的三角形的三條邊a、b、c 的長度,計算并依次輸出三角形的周長和面積,結(jié)果嚴格保留2位小數(shù)。測試用例的數(shù)據(jù)保證三角形三邊數(shù)據(jù)可以構(gòu)成三角形。 三角形面積計算公式: ,其中s=(a+b+c)/2。 ?第2關(guān):三角函數(shù)計算 根據(jù)下面公式 計

    2024年02月08日
    瀏覽(95)
  • 廣西民族大學(xué)高級人工智能課程—頭歌實踐教學(xué)實踐平臺—機器翻譯--English to Chinese

    廣西民族大學(xué)高級人工智能課程—頭歌實踐教學(xué)實踐平臺—機器翻譯--English to Chinese

    任務(wù)描述 本關(guān)任務(wù):基于機器學(xué)習(xí)的思想,是一種數(shù)據(jù)驅(qū)動的研究思想,因此首先要對準備研究的數(shù)據(jù)進行處理。對于機器翻譯模型,數(shù)據(jù)預(yù)處理主要分為兩個方面: 標準化自然語言語句的格式 構(gòu)建訓(xùn)練所用的語言詞典 將語詞轉(zhuǎn)化為向量 相關(guān)知識 為了完成本關(guān)任務(wù),你需

    2024年02月19日
    瀏覽(36)
  • 頭歌實踐教學(xué)平臺-Linux網(wǎng)絡(luò)實戰(zhàn)(一)-DNS配置(Ubuntu系統(tǒng))——保姆級教程

    頭歌實踐教學(xué)平臺-Linux網(wǎng)絡(luò)實戰(zhàn)(一)-DNS配置(Ubuntu系統(tǒng))——保姆級教程

    見者有緣,緣來好運。誠邀各位圍觀我的博客【CS_GUIDER】: 我的云服務(wù)器到期了,所以這里放兩個部署在碼云和 GitHub 的鏈接: https://wlei224.gitee.io (Gitee托管,速度極快) https://wl2o2o.github.io(Github托管,點擊有╰ °▽° ╯) ** 我的開源博客涵蓋了 八股文 、 Java基礎(chǔ) 、 JVM

    2023年04月20日
    瀏覽(133)
  • JDBC增刪改查 頭歌實踐教學(xué)Java

    JDBC增刪改查 頭歌實踐教學(xué)Java

    ? ?

    2024年02月04日
    瀏覽(35)
  • 頭歌:《C語言程序設(shè)計編程實踐任務(wù)》循環(huán)結(jié)構(gòu)程序設(shè)計 教學(xué)團隊:祁文青

    頭歌:《C語言程序設(shè)計編程實踐任務(wù)》循環(huán)結(jié)構(gòu)程序設(shè)計 教學(xué)團隊:祁文青

    任務(wù):求1000以內(nèi)所有的水仙花數(shù)。若一個 3 位整數(shù)的各位數(shù)字的立方之和等于這個整數(shù),稱之為“水仙花數(shù)”。 注: 前面題目寫過,取余可以提取刀整數(shù)的末尾數(shù)字,只要逐步提取出來判斷就行。 不能改變x的值(如x10),否則循環(huán)一直無法達到x1000,會陷入死循環(huán)。 任務(wù):輸

    2024年02月05日
    瀏覽(28)
  • 礦物鑒定VR實踐教學(xué)平臺:打造全新的沉浸式學(xué)習(xí)體驗

    礦物鑒定VR實踐教學(xué)平臺:打造全新的沉浸式學(xué)習(xí)體驗

    在科技的幫助下,我們的學(xué)習(xí)和培訓(xùn)方式正在發(fā)生著深刻的變化。其中,虛擬現(xiàn)實(VR)技術(shù)帶來的沉浸式學(xué)習(xí)體驗,為我們提供了一種全新的學(xué)習(xí)和實踐方式。本文將詳細介紹一款使用VR技術(shù)的教學(xué)工具—— 礦物鑒定VR實踐教學(xué)平臺 。 礦物鑒定VR實踐教學(xué)平臺由廣州華銳互

    2024年02月07日
    瀏覽(29)
  • 構(gòu)建之法 - 軟件工程實踐教學(xué):一線教師的13問

    構(gòu)建之法 - 軟件工程實踐教學(xué):一線教師的13問

    福州大學(xué)單紅老師的軟工課程總結(jié) 單紅?師在總結(jié)中,提出了13條疑惑,《構(gòu)建之法》的作者鄒欣?師就單紅?師提出的每?條疑惑,給出了??的思考,與他進?探討交流。歡迎你也來參與?起討論。 1. 關(guān)于軟件工程和軟件工程實踐課,安排時機的問題?目前是大三下,對

    2024年02月13日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包