資料庫基本SQL語句 巢狀查詢

2021-08-21 11:57:30 字數 491 閱讀 3720

查詢科目名稱為「語文「的所有科目成績:

select * from scores where subject_id in (select id from subject where names='語文')

(在where子句中對於能巢狀的子查詢的數目沒有限制,不過在實際使用時由於效能的限制,不能巢狀太多的子查詢,對於資料量較大的表,不能使用上述巢狀查詢。)

查詢所有學生的科目編碼為『yw』成績,顯示班級名稱,學生姓名,分數(student,grade,score)

select c.names,d.names as gradename,c.score from (select a.names,a.grade_id,b.score from student a,scores b where a.id=b.student_id and b.subject_id='yw') c,grade d where c .grade_id=d.id

資料庫基本sql語句

建立資料庫 1 如果不存在就新建資料庫,使用utf 8編碼格式,預設使用utf8排序。2create database ifnot exists test default character setutf8 collate utf8 general ci3 刪除資料庫 4drop database ...

資料庫SQL語句查詢

新手小白菜一枚,求知 查詢所有同學的學號 姓名 選課數 總成績 select t1.stuid,t1.stuname,count t2.courseid sum score from tblstudent t1,tblscore t2 where t1.stuid t2.stuid group by...

sql巢狀查詢語句

use adventureworks goselect distinct c.lastname,c.firstname from person.contact c join humanresources.employee e on e.contactid c.contactid where empl...