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

數(shù)據(jù)庫多表查詢作業(yè)

這篇具有很好參考價(jià)值的文章主要介紹了數(shù)據(jù)庫多表查詢作業(yè)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

數(shù)據(jù)庫多表查詢作業(yè)

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle
數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle
數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle
創(chuàng)建數(shù)據(jù)庫
數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle
插入數(shù)據(jù)

mysql> insert into student values(901,'張老大','男',1985,'計(jì)算機(jī)系','北京市海淀區(qū)'),
    -> (902,'張老二','男',1986,'中文系','北京市昌平市'),
    -> (903,'張三','女',1990,'中文系','湖南省永州市'),                                           -> (904,'李四','男',1990,'英語系','遼寧省阜新市'),                                           -> (905,'王五','女',1991,'英語系','福建省廈門市'),
    -> (906,'王六','男',1988,'計(jì)算機(jī)系','湖南省衡陽市');

mysql> insert into score values(null,901,'計(jì)算機(jī)',98),
    -> (null,901,'英語',80),
    -> (null,902,'計(jì)算機(jī)',65),
    -> (null,902,'中文',88),
    -> (null,903,'中文',95),
    -> (null,904,'計(jì)算機(jī)',70),
    -> (null,904,'英語',92),
    -> (null,905,'英語',94),
    -> (null,906,'計(jì)算機(jī)',90),
    -> (null,906,'英語',85);

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle
1.查詢student表的所有記錄

mysql> select * from student;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

2.查詢student表的第2條到4條記錄

mysql> select * from student limit 1,3;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

3.從student表查詢所有學(xué)生的學(xué)號(hào)(id)、姓名
(name)和院系(department)的信息

mysql> select id as 學(xué)號(hào),name as 姓名,department as 院系 from student;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

4.從student表中查詢計(jì)算機(jī)系和英語系的學(xué)生的信息

mysql> select * from student where department='計(jì)算機(jī)系' or department='英語系';

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

5.從student表中查詢年齡18~22歲的學(xué)生信息

mysql> select *,year(curdate())-birth as age from student where year(curdate())-birth between 18 and 22;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

6.從student表中查詢每個(gè)院系有多少人

mysql> select department as 院系,count(*) as 人數(shù) from student group by department;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

7.從score表中查詢每個(gè)科目的最高分

mysql> select c_name as 科目,max(grade) as 最高分 from score group by c_name;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

8.查詢李四的考試科目(c_name)和考試成績(grade)

mysql> select name as 姓名,c_name as 科目,grade as 成績 from student
    -> inner join score on student.id=score.stu_id
    -> where name='李四';

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

9.用連接的方式查詢所有學(xué)生的信息和考試信息

mysql> select * from student iudent inner join score on student.id=score.stu_id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

10.計(jì)算每個(gè)學(xué)生的總成績

mysql> select name as 姓名,sum(grade) as 總成績 from student
    -> inner join score on student.id=score.stu_id
    -> group by name;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

11.計(jì)算每個(gè)考試科目的平均成績

mysql> select avg(grade) from score group by c_name;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

12.查詢計(jì)算機(jī)成績低于95的學(xué)生信息

mysql> select * from student
    -> inner join (select stu_id,c_name,grade from score where grade<95 and c_name='計(jì)算機(jī)') as stu
    -> on student.id=stu.stu_id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

13.查詢同時(shí)參加計(jì)算機(jī)和英語考試的學(xué)生的信息

獲取同時(shí)考計(jì)算機(jī)和英語的學(xué)生ID

select * from score where c_name='英語') as sc2 where sc1.stu_id=sc2.stu_id

根據(jù)ID獲取學(xué)生信息

mysql> select * from student inner join (select sc1.stu_id from (select * from score where c_name='計(jì)算機(jī)') as sc1,(select * from score where c_name='英語') as sc2 where sc1.stu_id=sc2.stu_id) as sc on student.id=sc.stu_id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

14.將計(jì)算機(jī)考試成績按從高到低進(jìn)行排序

mysql> select * from score where c_name='計(jì)算機(jī)' order by grade desc;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

15.從student表和score表中查詢出學(xué)生的學(xué)號(hào),然后合并查詢結(jié)果

mysql> select student.id,score.stu_id from student inner join (select distinct stu_id from score) as score on student.id=score.stu_id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

16.查詢姓張或者姓王的同學(xué)的姓名、院系和考試科目及成績

mysql> select stu.name as 姓名, stu.department as 院系, score.c_name as 科目,score.grade as  成績
    -> from score inner join
    -> (select * from student where name like '張%' or name like '王') as stu
    -> on score.stu_id=stu.id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle

17.查詢都是湖南的學(xué)生的姓名、年齡、院系和考試科目及成績

mysql> select stu.name as 姓名,year(curdate())-stu.birth as age,stu.department as 院系,score.c_name as 科目,score.grade as 成績
    -> from score
    -> inner join
    -> (select * from student where address like '%湖南%') as stu
    -> on score.stu_id=stu.id;

數(shù)據(jù)庫多表查詢作業(yè),數(shù)據(jù)庫,數(shù)據(jù)庫,oracle文章來源地址http://www.zghlxwxcb.cn/news/detail-567882.html

到了這里,關(guān)于數(shù)據(jù)庫多表查詢作業(yè)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

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

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

相關(guān)文章

  • 數(shù)據(jù)庫多表查詢練習(xí)題

    數(shù)據(jù)庫多表查詢練習(xí)題

    二、多表查詢 1. 創(chuàng)建 student 和 score 表 CREATE TABLE student ( id INT ( 10 ) NOT NULL UNIQUE PRIMARY KEY , name VARCHAR ( 20 ) NOT NULL , sex VARCHAR ( 4 ) , birth YEAR , department VARCHAR ( 20 ) , address VARCHAR ( 50 ) ); 創(chuàng)建 score 表。 SQL 代碼如下: CREATE TABLE score ( id INT ( 10 ) NOT NULL UNIQUE PRIMARY KEY AUTO_INCREMENT , stu_

    2024年01月17日
    瀏覽(36)
  • MySQL數(shù)據(jù)庫基礎(chǔ)(三):多表查詢,子查詢,開窗函數(shù)

    MySQL數(shù)據(jù)庫基礎(chǔ)(三):多表查詢,子查詢,開窗函數(shù)

    表與表之間的關(guān)系 在SQL語句中,數(shù)據(jù)表與數(shù)據(jù)表之間,如果存在關(guān)系,一般一共有3種情況: ① 一對(duì)一關(guān)系(高級(jí)) 比如有A、B兩張表,A表中的每一條數(shù)據(jù),在B表中有一條唯一的數(shù)據(jù)與之對(duì)應(yīng)。 用戶表user user_id(用戶編號(hào)) 賬號(hào)username 密碼password 001 admin admin888 002 itheima

    2024年02月12日
    瀏覽(26)
  • Oracle數(shù)據(jù)庫update語句用法,多表批量更新對(duì)應(yīng)的字段值

    Oracle數(shù)據(jù)庫update語句用法,多表批量更新對(duì)應(yīng)的字段值

    日常工作經(jīng)常會(huì)遇到參照某個(gè)表格,更新主表對(duì)應(yīng)字段的值 一般可以用excel的VLOOKup函數(shù)進(jìn)行查找匹配,但是這種方法需要將表從數(shù)據(jù)庫中導(dǎo)出,更新完了之后再導(dǎo)回?cái)?shù)據(jù)庫中。 我們用update語句可以很方便在數(shù)據(jù)庫里完成更新。 語句: update 要修改數(shù)據(jù)的表名 set 修改的列1=(

    2024年02月06日
    瀏覽(23)
  • 【MySQL數(shù)據(jù)庫 | 第十三篇】多表查詢

    【MySQL數(shù)據(jù)庫 | 第十三篇】多表查詢

    多表查詢是指在一個(gè)SQL語句中使用多個(gè)表進(jìn)行數(shù)據(jù)查詢和操作。多表查詢可以對(duì)數(shù)據(jù)表之間的關(guān)系進(jìn)行查詢,例如可以通過連接多個(gè)表來獲取更完整的數(shù)據(jù)信息。關(guān)于單表查詢我們也介紹過,已經(jīng)整理成文章發(fā)布:【MySQL數(shù)據(jù)庫 | 第九篇】DQL操作_我是一盤牛肉的博客-CSDN博客

    2024年02月08日
    瀏覽(28)
  • ⑧【MySQL】數(shù)據(jù)庫查詢:內(nèi)連接、外連接、自連接、子查詢、多表查詢

    ⑧【MySQL】數(shù)據(jù)庫查詢:內(nèi)連接、外連接、自連接、子查詢、多表查詢

    個(gè)人簡介:Java領(lǐng)域新星創(chuàng)作者;阿里云技術(shù)博主、星級(jí)博主、專家博主;正在Java學(xué)習(xí)的路上摸爬滾打,記錄學(xué)習(xí)的過程~ 個(gè)人主頁:.29.的博客 學(xué)習(xí)社區(qū):進(jìn)去逛一逛~ 多表關(guān)系 : 一對(duì)一 :在 任意一方 加入外鍵,關(guān)聯(lián)另一方的主鍵,并設(shè)置外鍵為唯一(UNIQUE)。 一對(duì)多(

    2024年02月05日
    瀏覽(23)
  • [SQL Server]數(shù)據(jù)庫入門之多表查詢

    [SQL Server]數(shù)據(jù)庫入門之多表查詢

    ?? 博客主頁:博主鏈接 ?? 本文由 M malloc 原創(chuàng),首發(fā)于 CSDN?? ?? 學(xué)習(xí)專欄推薦:LeetCode刷題集! ?? 歡迎點(diǎn)贊 ?? 收藏 ?留言 ?? 如有錯(cuò)誤敬請(qǐng)指正! ?? 未來很長,值得我們?nèi)Ρ几案篮玫纳? ------------------??分割線??------------------------- —————————

    2024年02月08日
    瀏覽(88)
  • 數(shù)據(jù)庫——DAY4(練習(xí)-在表中查找數(shù)據(jù)-多表查詢)

    數(shù)據(jù)庫——DAY4(練習(xí)-在表中查找數(shù)據(jù)-多表查詢)

    一、實(shí)驗(yàn)要求(多表查詢) 素材: 1.創(chuàng)建student和score表 CREATE TABLE student ( id INT(10) NOT NULL UNIQUE PRIMARY KEY , name VARCHAR(20) NOT NULL , sex VARCHAR(4) , birth YEAR, department VARCHAR(20) , address VARCHAR(50) ); 創(chuàng)建score表。 SQL代碼如下: CREATE TABLE score ( id INT(10) NOT NULL UNIQUE PRIMARY KEY AUTO_INCREMENT , stu

    2024年01月18日
    瀏覽(17)
  • 數(shù)據(jù)庫系統(tǒng)頭歌實(shí)驗(yàn)二 SQL的多表查詢

    數(shù)據(jù)庫系統(tǒng)頭歌實(shí)驗(yàn)二 SQL的多表查詢

    第一關(guān):等值連接:求S表和J表城市相同的等值連接(列順序還是按照S、J表) 工程項(xiàng)目表J由工程項(xiàng)目代碼(JNO)、工程項(xiàng)目名(JNAME)、工程項(xiàng)目所在城市(CITY)組成。 供應(yīng)商表S由供應(yīng)商代碼(SNO)、供應(yīng)商姓名(SNAME)、供應(yīng)商狀態(tài)(STATUS)、供應(yīng)商所在城市(CITY)組成. S表如下圖

    2024年02月07日
    瀏覽(21)
  • 【從刪庫到跑路】MySQL數(shù)據(jù)庫的查詢(單表查詢,多表查詢,內(nèi)外連接,聯(lián)合查詢,子查詢)

    【從刪庫到跑路】MySQL數(shù)據(jù)庫的查詢(單表查詢,多表查詢,內(nèi)外連接,聯(lián)合查詢,子查詢)

    ??專欄【MySQL】 ??喜歡的詩句:更喜岷山千里雪 三軍過后盡開顏。 ??音樂分享【如愿】 大一同學(xué)小吉,歡迎并且感謝大家指出我的問題?? 在項(xiàng)目開發(fā)中,在進(jìn)行數(shù)據(jù)庫表結(jié)構(gòu)設(shè)計(jì)時(shí),會(huì)根據(jù)業(yè)務(wù)需求以及業(yè)務(wù)模塊之間的關(guān)系,分析并設(shè)計(jì)表結(jié)構(gòu),由于業(yè)務(wù)之間相互關(guān)聯(lián)

    2024年02月10日
    瀏覽(29)
  • 數(shù)據(jù)庫作業(yè)——select查詢操作

    數(shù)據(jù)庫作業(yè)——select查詢操作

    創(chuàng)建數(shù)據(jù)庫 插入數(shù)據(jù) 1、顯示所有職工的基本信息。 2、查詢所有職工所屬部門的部門號(hào),不顯示重復(fù)的部門號(hào)。 3、求出所有職工的人數(shù)。 4、列出最高工和最低工資。 5、列出職工的平均工資和總工資。 6、創(chuàng)建一個(gè)只有職工號(hào)、姓名和參加工作的新表,名為工作日期表。

    2024年02月13日
    瀏覽(28)

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

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包