mysql in 的兩種用法,mysqlin兩種用法

來源:互聯網
上載者:User

mysql in 的兩種用法,mysqlin兩種用法

簡述MySQL 的in 的兩種用法:

他們分別是在 in 關鍵字後跟一張表(記錄集),以及在in後面加上字串集。

先講後面跟著一張表的。


首先闡述三張表的結構:

s(sno,sname.sex,age,dept)   //學生資訊表

c(cno,cname,tname)      //課程資訊表

sc(sno,cno,grade)              //課程選修資訊表

update sc set grade = 0 where sc.cno in (select cno from c where c.cname = '物理') and sc.grade < 60; 比如說這條sql語句 ,這條sql語句是將課程為物理的不及格的分數設定為0分。

這個例子裡的in後面就跟著一張由select語句 產生的一張暫存資料表。


好,那麼現在再來看下面的in後面跟著一個字串集,其實也不見得非得是字串集。

select * from s where sname in ('aaa','bbb','ccc');




相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.