SQL內(nèi)功心法之乾坤大挪移

  SQL: 指結(jié)構(gòu)化查詢語(yǔ)言,全稱是 Structured Query Language。
SQL語(yǔ)言包括三種主要程序設(shè)計(jì)語(yǔ)言類別的語(yǔ)句:數(shù)據(jù)定義語(yǔ)言(DDL),數(shù)據(jù)操作語(yǔ)言(DML)及數(shù)據(jù)控制語(yǔ)言(DCL)。
DCL:數(shù)據(jù)庫(kù)控制語(yǔ)言,Data Control Language,  用來(lái)設(shè)置或更改數(shù)據(jù)庫(kù)用戶或角色權(quán)限的語(yǔ)句,【grant、remove,deny】
DML:數(shù)據(jù)操縱語(yǔ)言,Data Manipulation Language ,命令使用戶能夠操作已有數(shù)據(jù)庫(kù)中的數(shù)據(jù)的計(jì)算機(jī)語(yǔ)言 【Insert、delete、update】,處理表數(shù)據(jù)
DDL:數(shù)據(jù)庫(kù)模式定義語(yǔ)言,Data Definition Language ,是用于描述數(shù)據(jù)庫(kù)中要存儲(chǔ)的現(xiàn)實(shí)世界實(shí)體的語(yǔ)言【create,add,alter,drop】處理表結(jié)構(gòu)
DQL:數(shù)據(jù)查詢語(yǔ)言,Data Query Language SELECT ,【select】
----------------------------------表結(jié)構(gòu)----------------------------------------------------
--學(xué)生表 Student(編號(hào)student_code、姓名student_name、年齡student_age、性別student_sex)
--課程表 Course(課程編號(hào)course_code、課程名稱course_name、教師編號(hào)teacher_code)
--成績(jī)表 Score(學(xué)生編號(hào)student_code、課程編號(hào)course_code、成績(jī)score)
--教師表 Teacher(教師編號(hào)teacher_code、姓名teacher_name)
創(chuàng)建表:
CREATE TABLE Student (
`student_code`  varchar(255) NOT NULL COMMENT '學(xué)號(hào)' ,
`student_name`  varchar(255) NULL COMMENT '學(xué)生姓名' ,
`student_sex`  char(1) NULL COMMENT '性別' ,
`student_age`  varchar(255) NULL COMMENT '年齡' ,
`create_by`  varchar(255) NULL COMMENT '創(chuàng)建人' ,
`create_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '創(chuàng)建日期' ,
`update_by`  varchar(255) NULL COMMENT '更新人' ,
`updtae_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時(shí)間' ,
PRIMARY KEY (`student_code`)
);
CREATE TABLE Course (
`course_code`  varchar(255) NOT NULL COMMENT '課程號(hào)' ,
`course_name`  varchar(255) NULL COMMENT '課程姓名' ,
`teacher_code`  varchar(255) NULL COMMENT '教師編碼' ,
`create_by`  varchar(255) NULL COMMENT '創(chuàng)建人' ,
`create_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '創(chuàng)建日期' ,
`update_by`  varchar(255) NULL COMMENT '更新人' ,
`updtae_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時(shí)間' ,
PRIMARY KEY (`course_code`)
);
CREATE TABLE Score (
`student_code`  varchar(255) NOT NULL COMMENT '學(xué)號(hào)' ,
`course_code`  varchar(255) NULL COMMENT '課程編碼' ,
`score`  int(100) NULL COMMENT '成績(jī)' 
);
CREATE TABLE Teacher (
`teacher_code`  varchar(255) NOT NULL COMMENT '教師編號(hào)' ,
`teacher_name`  varchar(255) NULL COMMENT '教師姓名' ,
`create_by`  varchar(255) NULL COMMENT '創(chuàng)建人' ,
`create_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '創(chuàng)建日期' ,
`update_by`  varchar(255) NULL COMMENT '更新人' ,
`updtae_date`  datetime NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新時(shí)間' ,
PRIMARY KEY (`teacher_code`)
);
插入數(shù)據(jù):
---插入數(shù)據(jù)--
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709001', 'A001', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709002', 'A002', '女', '22', 'system', '2017-01-03 15:08:38', 'system', '2017-01-03 15:08:38');
INSERT INTO  `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709003', 'A003', '女', '22', 'system', '2017-01-03 15:08:38', 'system', '2017-01-03 15:08:38');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709004', 'A004', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709005', 'A005', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709006', 'A006', '女', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709007', 'A007', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709008', 'A008', '女', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709009', 'A009', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709010', 'A010', '女', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709011', 'A011', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');
INSERT INTO `student` (`student_code`, `student_name`, `student_sex`, `student_age`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('201709012', 'A012', '男', '22', 'system', '2017-01-03 15:08:23', 'system', '2017-01-03 15:08:23');

---插入數(shù)據(jù)--
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Chinese', '語(yǔ)文', 'T001', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Math', '數(shù)學(xué)', 'T002', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('English', '英語(yǔ)', 'T003', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Physics', '物理', 'T004', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Political', '政治', 'T005', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Organism', '生物', 'T006', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Geography', '地理', 'T007', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('History', '歷史', 'T008', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');
INSERT INTO `course` (`course_code`, `course_name`, `teacher_code`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('Chemistry', '化學(xué)', 'T009', 'system', '2017-01-03 15:19:18', 'system', '2017-01-03 15:19:32');

---插入數(shù)據(jù)--
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709001', 'Political', '99');


INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709002', 'Political', '99');


INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709003', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709004', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709005', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709006', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709007', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709008', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709009', 'Political', '99');

INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Chemistry', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Chinese', '90');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'English', '97');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Geography', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'History', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Math', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Organism', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Physics', '99');
INSERT INTO `score` (`student_code`, `course_code`, `score`) VALUES ('201709010', 'Political', '99');

---插入數(shù)據(jù)--
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T001', '王羲之', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T002', '趙匡胤', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T003', '趙明', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T004', '燕十三郎', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T005', '龍吟', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T006', '方言', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T007', '彭松', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T008', '唐宋', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
INSERT INTO `teacher` (`teacher_code`, `teacher_name`, `create_by`, `create_date`, `update_by`, `updtae_date`) VALUES ('T009', '張三豐', 'system', '2017-01-03 15:42:06', 'system', '2017-01-03 15:42:16');
場(chǎng)景測(cè)試:
-- 1.查詢“A”課程比“B”課程成績(jī)高的所有學(xué)生的學(xué)號(hào)
 SELECT
	student.student_code AS "StudentCode",
	student.student_name AS "StudentName"
FROM
	Student student
WHERE
	(
		SELECT
			score1.score 
		FROM
			Score score1
		WHERE
			score1.student_code = student.student_code
		AND score1.course_code = 'Chemistry' -- A課程
	) > (
		SELECT
			score2.score 
		FROM
			Score score2
		WHERE
			score2.student_code = student.student_code
		AND score2.course_code = 'Chinese' -- B課程
	);

--2.查詢平均成績(jī)大于90分的同學(xué)的學(xué)號(hào)和平均成績(jī)
 SELECT
	score.student_code AS "StudentCode",
	AVG(score.score) AS " AVGScore"
FROM
	Score score
GROUP BY
	score.score
HAVING
	AVG(score.score) > 90


--3.查詢所有同學(xué)的學(xué)號(hào)、姓名、選課數(shù)、總成績(jī); 
SELECT
	student.student_code AS "StudentCode",--學(xué)號(hào)
	student.student_name AS "StudentName",--姓名
	COUNT(score.course_code) AS "SelectCourse",--選課數(shù)
	SUM(score.score) AS "SumScore"--總成績(jī)
FROM
	Student student
LEFT JOIN Score score ON score.student_code = student.student_code
GROUP BY
	student.student_code,
	student.student_name;

--4、查詢姓“張”的老師的個(gè)數(shù); 
SELECT
	Count(*)
FROM
	Teacher teacher
WHERE
	teacher.teacher_name LIKE '張%';

--5.查詢沒(méi)有學(xué)過(guò)“張三豐”老師課的同學(xué)的學(xué)號(hào)、姓名; 
SELECT
	student.student_code AS "StudentCode",
	student.student_name AS "StudentName"
FROM
	Student student
WHERE
	student.student_code NOT IN (
		SELECT
    DISTINCT
			(score.student_code)
		FROM
			Score score,
			Course course,
			Teacher teacher
		WHERE
			score.course_code = course.course_code
		AND teacher.teacher_code = course.course_code
		AND teacher.teacher_name = '張三豐'
	);

當(dāng)前文章:SQL內(nèi)功心法之乾坤大挪移
本文來(lái)源:http://muchs.cn/article38/ipjjpp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、搜索引擎優(yōu)化外貿(mào)網(wǎng)站建設(shè)、商城網(wǎng)站、小程序開發(fā)、電子商務(wù)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)