日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql三表where查询_mysql三表查询sql语句

發布時間:2025/3/12 数据库 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql三表where查询_mysql三表查询sql语句 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

表結構:

Student學生表(學號、姓名、性別、年齡、編輯)

Course課程表(編號、課程名稱)

sc選課表(選課編號、學號、課程編號、成績)

(1)寫一個SQL語句,查詢選修了“計算機原理”的學生學號和姓名

(2)寫一個SQL語句,查詢“小明”同學選修的課程名稱

(3)寫一個SQL語句,查詢選修了5門課程的學生學號和姓名

答案:

(1)

select student.stu_no,student.stu_name

from student,course,sc

where course.c_no=sc.c_no and sc.stu_no=student.stu_no and course.c_name='計算機原理';

(2)

select course.c_name,student.stu_name

from student,course,sc

where student.stu_name='小明' and student.stu_no=sc.stu_no and sc.c_no=course.c_no;

(3)

select student.stu_no,stu_name

from student,course,sc

where student.stu_no=sc.stu_no and sc.c_no=course.c_no

group by student.stu_no

having count(*)=5

建表及插入數據可參考如下語句:

create table student(

stu_no int,

stu_name varchar(10),

sex char(1),

age int(3),

edit varchar(20)

);

insert into student values

(1,'wang','男',21,'hello'),

(2,'小明','女',22,'haha2'),

(3,'hu','女',23,'haha3'),

(4,'li','男',25,'haha4');

create table course(

c_no int,

c_name varchar(10)

);

insert into course values

(1,'計算機原理'),

(2,'java'),

(3,'c'),

(4,'php'),

(5,'py');

create table sc(

sc_no int,

stu_no int,

c_no int,

score int(3)

);

insert into sc values

(1,1,1,80),

(2,2,2,90),

(3,2,1,85),

(4,2,3,70),

(5,2,4,95),

(6,2,5,89);

總結

以上是生活随笔為你收集整理的mysql三表where查询_mysql三表查询sql语句的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。