create database school;
use school;
create table student(
sno varchar(20) not null primary key,-- 學(xué)號
sname varchar(20) not null, -- 姓名
ssex varchar(20) not null, -- 性別
sbirthday datetime, -- 出生年月
class varchar(20) -- 班級
);
create table course(
cno varchar(20) not null primary key, -- 課程號
cname varchar(20) not null, -- 課程名稱
tno varchar(20) not null references tearcher(tno) -- 教工編號
);
create table score(
sno varchar(20) not null references student(sno), -- 學(xué)號
cno varchar(20) not null references course(cno), -- 課程號
degree decimal(4,1) -- 成績
);
create table tearcher(
tno varchar(20) not null primary key, -- 教工編號
tname varchar(20) not null , -- 教工姓名
tsex varchar(20) not null , -- 教工性別
tbirthday datetime ,-- 教工出生年月
prof varchar(20) , -- 職稱
depart varchar(20) not null -- 教工所在部門
);
insert into student values ('108','曾華','男','1977-09-01','95033'),('105','匡明','男','1975-10-02','95031'),
('107','王麗','女','1976-01-23','95033'),
('101','李軍','男','1976-02-20','95033'),
('109','王芳','女','1975-02-10','95031'),
('103','陸軍','男','1974-06-03','95031')
select * from student;
insert into course values ('3-105','計算機導(dǎo)論','825'),
('3-245','操作系統(tǒng)','804'),
('6-166','數(shù)字電路','856'),
('9-888','高等數(shù)學(xué)','831')
select * from course;
insert into score values ('103','3-245','86'),
('105','3-245','75'),
('109','3-245','68'),
('103','3-105','92'),
('105','3-105','88'),
('109','3-105','76'),
('101','3-105','64'),
('107','3-105','91'),
('108','3-105','78'),
('101','6-166','85'),
('107','6-166','79'),
('108','6-166','81')
select * from score;
insert into tearcher values ('804','李誠','男','1958-12-02','副教授','計算機系'),
('856','張旭','男','1969-03-12','講師','電子工程系'),
('825','王萍','女','1972-05-05','助教','計算機系'),
('831','劉兵','女','1977-08-14','助教','電子工程系')
select * from tearcher;
-- 1.查詢student 表中的所有記錄的sname , ssex, 和 class列(查詢指定列)
select sname as 姓名,ssex as 性別,class as 班級 from student;
-- 2.查詢教師所有的單位即不重復(fù)的depart列
select distinct depart from tearcher;
-- 3.查詢student 表的所有記錄
select * from student;
-- 4.查詢score 表中成績在60到80之間的所有記錄殊校。
select * from score where degree between 60 and 80;
select * from score where degree >=60 and degree <=80;
-- 5.查詢score表中成績?yōu)?5甚颂,86或88的記錄双肤。
select * from score where degree=85 || degree=86 || degree=88;
select * from score where degree in (85,86,88);
-- 6.查詢student表中"95031"班或性別為"女"的同學(xué)記錄
select * from student where class='95031' || ssex = '女';
-- 7.以class降序查詢student表的所有記錄
select * from student order by class desc;
-- 8.以cno升序、degree降序查詢score表的所有記錄。
select * from score order by cno,degree desc;
-- 9.查詢"95031"班的學(xué)生人數(shù)凳干。
select count(*) 人數(shù) from student where class='95031';
-- 10.查詢score表中的最高分的學(xué)生學(xué)號和課程號
select sno,cno from score order by degree desc limit 1;
select sno,cno from score where degree=(select max(degree) from score);
mysql練習(xí)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事」技耍” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵忌怎,是天一觀的道長籍滴。 經(jīng)常有香客問我,道長榴啸,這世上最難降的妖魔是什么异逐? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮插掂,結(jié)果婚禮上灰瞻,老公的妹妹穿的比我還像新娘。我一直安慰自己辅甥,他們只是感情好酝润,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著璃弄,像睡著了一般要销。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上夏块,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼歇由!你這毒婦竟也來了卵牍?” 一聲冷哼從身側(cè)響起,我...
- 正文 年R本政府宣布袁梗,位于F島的核電站,受9級特大地震影響憔古,放射性物質(zhì)發(fā)生泄漏遮怜。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一鸿市、第九天 我趴在偏房一處隱蔽的房頂上張望锯梁。 院中可真熱鬧,春花似錦焰情、人聲如沸陌凳。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽合敦。三九已至,卻和暖如春验游,著一層夾襖步出監(jiān)牢的瞬間充岛,已是汗流浹背。 一陣腳步聲響...
推薦閱讀更多精彩內(nèi)容
- -- 40权悟、查詢選修"張三"老師所授課程的學(xué)生中,成績最高的學(xué)生信息及其成績 -- 41推盛、查詢不同課程成績相同的學(xué)...
- mysql練習(xí) 涉及到的表: 員工表: 部門表: 工資等級表: 1.取得每個部門最高薪水的人員名稱 2.求出薪水在...
- 16宿命:用概率思維提高你的勝算 以前的我是風(fēng)險厭惡者峦阁,不喜歡去冒險,但是人生放棄了冒險耘成,也就放棄了無數(shù)的可能榔昔。 ...
- 公元:2019年11月28日19時42分農(nóng)歷:二零一九年 十一月 初三日 戌時干支:己亥乙亥己巳甲戌當(dāng)月節(jié)氣:立冬...