mysql數據庫上機題_MYSQL數據庫練習題操作(select)大全

1、?查詢Student表中的所有記錄的Sname、Ssex和Class列。select sname,ssex,class fromstudent;2、查詢教師所有的單位即不重復的Depart列。select distinct depart fromteacher;3、?查詢Student表的所有記錄。select * fromstudent;4、?查詢Score表中成績在60到80之間的所有記錄。select * from score where degree>60 and degree<80;5、?查詢Score表中成績為85,86或88的記錄。select * from score where degree in (85,86,88);6、?查詢Student表中“95031”班或性別為“女”的同學記錄。select * from student where class like '95031' or ssex like '女';7、?以Class降序查詢Student表的所有記錄。select * from student order by class desc;8、?以Cno升序、Degree降序查詢Score表的所有記錄。select * from score order by cno asc , degree desc;9、?查詢“95031”班的學生人數。select count(*) from student group byclass;10、?查詢Score表中的最高分的學生學號和課程號。(子查詢或者排序)select * from score order by degree desc limit 1;

下面這個使用的連接查詢select max(degree) fromscore #先寫出score的最高分select * from score where degree = (select max(degree) fromscore);select sno,cno from score where degree = (select max(degree) fromscore);11、?查詢每門課的平均成績。select cno,count(*),avg(degree) from score group by cno having count(*); 多條查詢12、查詢Score表中至少有5名學生選修的并以3開頭的課程的平均分數。select cno,avg(degree) from score where cno like '3-105' and cno like '3%';select * from score group bydegree;select cno,count(*),avg(degree) from score where cno like '3%' group by cno having count(*) >= 5;select cno,count(*),avg(degree) from score where cno like '3%' group by cno having count(*) >= 5;13、查詢分數大于70,小于90的Sno列。select sno,degree from score where degree>70 and degree<90;select group_concat(sno) from score where degree>70 and degree<90;14、查詢所有學生的Sname、Cno和Degree列。(多表查詢)

student.sname,course.cno,score.degreeselect student.sname,course.cno,score.degree fromstudent,course,score;select sname,cno,degree from student join score on student.sno =score.sno;15、查詢所有學生的Sno、Cname和Degree列。

student.sno,course.cname,score.degreeselect student.sno,course.cname,score.degree fromstudent,course,score;select sno,cname,degree from score join course on course.cno =score.cno;16、查詢所有學生的Sname、Cname和Degree列。

student.sname,course.cname,score.degree;select student.sname,course.cname,score.degree fromstudent,course,score;select student.sname,course.cname,score.degree from student,course,score where sname between '李軍' and '王麗';select student.sname,cname,degree from student join score on student.sno = score.sno join course on course.cno =score.cno;17、查詢“95033”班學生的平均分。select sno from student where class = '95033';select avg(degree) from score where sno in(select sno from student where class = '95033');18、查詢選修“3-105”課程的成績高于“109”號同學成績的所有同學的記錄。select degree from score where sno = '109' and cno = '3-105';select sno,degree from score where degree > (select degree from score where sno = '109' and cno = '3-105');19、查詢score中選學多門課程的同學中分數為非最高分成績的記錄。select cno from score where (cno = '3-245' and cno = '3-105') or (cno = '3-245' and cno = '6-166') or (cno = '3-245' and cno = '6-166'); 這是個錯誤的select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score b where b.Cno =a.Cno)select * from Score a where Sno in (select Sno from Score group by Sno having count(*)>1 ) and Degree not in (select max(Degree) from Score a where Sno in (select Sno from Score group by Sno having count(*)>1))20、查詢成績高于學號為“109”、課程號為“3-105”的成績的所有記錄。select degree from score where sno = '109' and cno = '3-105';select * from score where degree > (select degree from score where sno = '109' and cno = '3-105');21、查詢和學號為108的同學同年出生的所有學生的Sno、Sname和Sbirthday列。select sbirthday from student where sno = '108';select sno,sname,sbirthday from student where sbirthday = (select sbirthday from student where sno = '108');22、查詢“張旭“教師任課的學生成績(姓名)。select tno from teacher where tname = '張旭'; #找出教師編號select cno from course where tno = (select tno from teacher where tname = '張旭'); #找出課程編號select sno,degree from score where cno = (select cno from course where tno = (select tno from teacher where tname = '張旭'));select student.sno,degree,sname from score join student on score.sno = student.sno where student.sno in (select sno from score where cno = (select cno from course where tno = (select tno from teacher where tname = '張旭')));23、查詢考計算機導論的學生成績select cno from course where cname = '計算機導論'; #找到課程編號3-105

select sno,degree from score where cno = (select cno from course where cname = '計算機導論');24、查詢李誠老師教的課程名稱select tno from teacher where tname = '李誠'; ##找到教師編號select cname from course where tno = (select tno from teacher where tname = '李誠');25、教高等數學的老師是哪個系的select tno from course where cname = '高等數學';select depart from teacher where tno = (select tno from course where cname = '高等數學');26、查詢選修某課程的同學人數多于5人的教師姓名。select cno,count(*) from score group by cno having count(*)>=5; #找出課程編號select tno from course where cno = (select cno from score group by cno having count(*)>=5);select tname from teacher where tno = (select tno from course where cno = (select cno from score group by cno having count(*)>=5));27、查詢95033班和95031班全體學生的記錄。select * from student group by class having count(*);select * from student order by class desc;28、查詢成績表中存在有85分以上成績的課程Cno.select cno,degree from score where degree>85;29、查詢出“計算機系“教師所教課程的成績表。select tno,tname from teacher where depart = '計算機系'#查出教師編號select cno from course where tno in (select tno from teacher where depart = '計算機系'); #查出課程編號select sno,cno,degree from score where cno in (select cno from course where tno in (select tno from teacher where depart = '計算機系'));30、查詢選修編號為“3-105”且成績高于選修編號為“3-245”課程的同學的 Cno、Sno和Degree.select max(degree) from score where cno = '3-245'; #先把選修編號為3-245課程的同學的最高成績查詢出來select cno,sno,degree from score where cno = '3-105' and degree > (select max(degree) from score where cno = '3-245');31、查詢所有教師和同學的name、sex和birthday.select tname as name,tsex as sex,tbirthday as birthday fromteacherunion

select sname,ssex,sbirthday fromstudent;32、查詢所有“女”教師和“女”同學的name、sex和birthday.select tname as name,tsex as sex,tbirthday as birthday from teacher where tsex = '女'

union

select sname,ssex,sbirthday from student where ssex = '女';33、查詢所有成績比3-105課程平均成績低的同學的成績表。select avg(degree) from score where cno = '3-105';select degree from score where degree < (select avg(degree) from score where cno = '3-105');34、查詢所有任課教師的Tname和Depart.select tname,depart fromteacher;35、查詢所有未講課的教師的Tname和Depart.select tno from course group bytno; #找出有課的老師的編號select tname,depart from teacher where not exists(select tno from course group bytno);36、查詢至少有2名男生的班號。#####################################################3

select ssex,class from student where ssex = '男' group byclass;select class from student where exists ((select ssex,class from student where ssex = '男' group by class) * 2);37、查詢Student表中不姓“王”的同學記錄。select sname from student where sname like '王%'

select sname from student where sname not in (select sname from student where sname like '王%');38、查詢Student表中每個學生的姓名和年齡。selectsname,select floor(datediff(curdate(),@birthday)/365.2422)39、查詢Student表中最大和最小的Sbirthday日期值。select max(sbirthday) as '最大日期' , min(sbirthday) as '最小日期' fromstudent;update student set sbirthday = '1995-07-11' where sno = '108';update student set sbirthday = '1820-05-01' where sno = '105';40、以班號和年齡從大到小的順序查詢Student表中的全部記錄。select * from student order by class desc,sbirthday desc;41、查詢“男”教師及其所上的課程。select tno from teacher where tsex = '男';select cname from course where tno in (select tno from teacher where tsex = '男');42、查詢最高分同學的Sno、Cno和Degree列。select max(degree) fromscoreselect score.sno,cno,degree fromstudentjoinscoreon student.sno =score.snowhere degree = (select max(degree) fromscore);43、查詢和“李軍”同性別的所有同學的Sname.select ssex from student where sname = '李軍';select sname from student where ssex = (select ssex from student where sname = '李軍');44、查詢和“李軍”同性別并同班的同學Sname.select class from student where sname = '李軍';select sname from student where ssex = (select ssex from student where sname = '李軍') and class = (select class from student where sname = '李軍');45、查詢所有選修“計算機導論”課程的“男”同學的成績表。select cno from course where cname = '計算機導論'; #根據課程表找到課程編號select sno from score where cno = (select cno from course where cname = '計算機導論'); #根據課程編號找到成績表里面的學生編號select sname from student where sno in (select sno from score where cno = (select cno from course where cname = '計算機導論')) and ssex = '男';

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/445848.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/445848.shtml
英文地址,請注明出處:http://en.pswp.cn/news/445848.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Java中<? super T>和List<? extends T>的區別

Java中<? super T>和List<? extends T>的區別 <? extends T> 下面通配符聲明List<? extends Number> foo3的賦值式是合法的&#xff1a; List<? extends Number> foo3 new ArrayList<Number>(); // Number "extends" …

mysql書寫規則_每天10分鐘帶你學會MySQL(二)SQL語句的基本書寫規則

SQL語句時必須要遵守一些規則。這些規則都非常簡單&#xff0c;接下來就讓我們逐一認識一下吧。1&#xff0c;SQL語句以分號(;)結尾。■SQL語句要以分號(;)結 尾一條SQL語句可以描述一個數據庫操作。在RDBMS當中&#xff0c;SQL語句也是逐條執行的。眾所周知&#xff0c;我們在…

《劍指Offer》52:兩個鏈表的第一個公共節點

題目 輸入兩個鏈表&#xff0c;找出它們的第一個公共節點。 public static class ListNode{public int val;public ListNode next;public ListNode(int val) {this.val val;} }分析 首先遍歷兩鏈表的長度。在第二次遍歷的時候&#xff0c;在較長的鏈表上先走若干步&#xf…

mysql win 64_win10下裝mysql-5.7.18-winx64

步驟1官網下載地址&#xff1a;https://dev.mysql.com/downloads/mysql/選擇手動安裝版&#xff1a;解壓到D盤mysql文件夾下&#xff1a;比以往的版本里缺少了兩個.ini文件&#xff0c;直接copy過來&#xff0c;進行修改,my.ini&#xff1a;[client]port3306default-character-…

《劍指Offer》62:圓圈中最后剩下的數字(約瑟夫環)

題目 0,1,2…,n-1這n個數字排成一個圓圈&#xff0c;從數字0開始&#xff0c;每次從這圓圈你刪除第m個數字。求出這個圓圈里剩下的最后一個數字。 例如&#xff0c;0、1、2、3、4這5個數字組成一個圓圈&#xff0c;從數字0開始每次刪除第3個數字&#xff0c;則刪除的前4個數字…

mysql數據庫老是被鎖怎么解決_Mysql數據庫全局鎖是如何引起的,如何解決?

2019-01-08 回答樂觀鎖與悲觀鎖不同的是&#xff0c;它是一種邏輯上的鎖&#xff0c;而不需要數據庫提供鎖機制來支持當數據很重要&#xff0c;回滾或重試一次需要很大的開銷時&#xff0c;需要保證操作的acid性質&#xff0c;此時應該采用悲觀鎖而當數據對即時的一致性要求不高…

我們邊吃曲奇邊聊——Cookie與Session那些事

Cookie與Session分別是什么&#xff1f; HTTP Cookie&#xff08;也叫 Web Cookie 或瀏覽器 Cookie&#xff09;是服務器發送到用戶瀏覽器并保存在本地的一小塊數據&#xff0c;它會在瀏覽器下次向同一服務器再發起請求時被攜帶并發送到服務器上。 通常&#xff0c;它用于告知…

mysql 不能添加外鍵 1215_MySQL錯誤1215:無法添加外鍵約束

我正在嘗試將新模式轉發工程到我的數據庫服務器上&#xff0c;但是我不知道為什么會收到此錯誤。我試圖在這里搜索答案&#xff0c;但是我發現的所有內容都說是將db引擎設置為Innodb或確保要用作外鍵的鍵是它們自己表中的主鍵。如果我沒記錯的話&#xff0c;我都做過這兩件事。…

JMH初體驗

什么是JMH JMH是 Java Microbenchmark Harness 的縮寫。中文意思大致是 “JAVA 微基準測試套件”。 基準測試是指通過設計科學的測試方法、測試工具和測試系統&#xff0c;實現對一類測試對象的某項性能指標進行定量的和可對比的測試。——百度百科 為什么要使用 JMH 基準測試…

java map取第一個元素_Java Set接口 Map 與枚舉

Set接口概述一個不包含重復元素的 collection。更確切地講&#xff0c;set 不包含滿足 e1.equals(e2) 的元素對 e1 和 e2&#xff0c;并且最多包含一個 null 元素特點Set接口是無序的 Set 是繼承于Collection的接口。它是一個不允許有重復元素的集合。Set可以存儲null值,但是nu…

Python中yield簡單用法

Python中yield簡單用法 你或許知道帶有yield的函數在Python中被稱之為generator&#xff0c;那何為 generator&#xff1f; 我們暫時拋開generator&#xff0c;先從一個常見編程題目開始&#xff0c;循序漸進了解yield的概念。 生成Fibonacci數列 Fibonacci數列是一個經典遞…

js 用下標獲取map值_js map方法處理返回數據,獲取指定數據簡寫方法

map方法處理返回數據&#xff0c;獲取指定數據簡寫方法前言后端返回數據為數組列表時&#xff0c;通常比較全面&#xff0c;包含了很多不需要的數據&#xff0c;可以通過 map 方法處理返回數據&#xff0c;篩選出想要的數據例如// 返回數據res [{id: 1,name: zhangsan,age: 16…

《Python Cookbook 3rd》筆記匯總

文章目錄一、數據結構二、字符串和文本三、數字、日期和時間四、迭代器與生成器五、文件與IO一、數據結構 標題關鍵詞1.1&#xff1a;拆分序列后賦值給多個變量可迭代對象、拆分賦值1.2&#xff1a;拆分任意長可迭代對象后賦值給多個變量可迭代對象、拆分賦值、星號表達式1.3&…

mysql hp ux_hp ux apa 切換

(HP-UX Only) OR - 1 heartbeat network using APA with 2 trunk members (HP-UX Only) OR - 1 heartbeat network with serial line (HP-UX Only) OR......一、 概述 HP 的 APA 軟件提供兩種網卡冗余切換模式,用以實現網絡高可用性...0x000000000000 hp_apa HP-UX 11i v3 Prer…

Python中[:]與[::]的用法

Python中[:]與[::]的用法 概述 [:]與[::]語法是通用序列操作&#xff08;Common Sequence Operations&#xff09;其中的兩個。用[:]或[::]對多數序列類型&#xff08;可變的或不可變的&#xff09;&#xff08;如字符串、列表等&#xff09;序列中元素進行截取。 [:]的用法…

mysql redis 中間件_Docker快速搭建Mysql社區版,Redis,MongoDb、MQ等等中間件。

一&#xff1a;安裝docker社區版。Centos系列(最好用7以上的版本&#xff0c;docker需要3.1以上的linux內核版本)sudo yum install docker-ce docker-ce-cli containerd.iosudo systemctl start dockersudo docker run hello-world如果你敲docker info需要root密碼&#xff0c;…

JavaScript中String的slice(),substr(),substring()三者區別

JavaScript中String的slice()&#xff0c;substr()&#xff0c;substring()三者區別 共同之處 從給定的字符串中截取片段&#xff0c;并返回全新的這片段的字符串對象&#xff0c;且不會改動原字符串。 具體不同之處 slice() str.slice(beginIndex[, endIndex])參數描述be…

pythontuple數據類型_數據類型-元組Tuple

Python Tuple用于存儲不可變python對象的序列。元組類似于列表&#xff0c;因為可以改變列表中存儲的項的值&#xff0c;而元組是不可變的&#xff0c;并且不能改變存儲在元組中的項的值。元組可以寫成用小括號括起來的逗號分隔值的集合。元組可以定義如下。T1 (101, "Ay…

《劍指Offer》24:反轉鏈表

題目 定義一個函數&#xff0c;輸入一個鏈表的頭節點&#xff0c;反轉鏈表并輸出反轉后鏈表的頭節點。鏈表節點定義如下&#xff1a; public static class ListNode{public int val;public ListNode next;public ListNode(int val) {this.val val;} }分析 方法一&#xff1…

python兩個for循環為什么第二個循環里值不變_兩個for循環,第二個只在第一個迭代python上執行...

我是一個pythonnoob&#xff0c;我試圖比較兩個文件中的行之間的值&#xff0c;如果行在第二個文件中&#xff0c;則輸出“line name”&#xff0c;然后輸出1&#xff1b;如果第二個文件中缺少該行&#xff0c;則輸出0。第一次迭代返回1&#xff0c;因為該行在第二個文件中&…