各位小夥伴們大家好,好久不見哈,在之前的文章中,小編介紹了一些資料庫的相關知識,這次小編要介紹的是MySQL當中的條件查詢。
條件查詢:where子句後跟條件。
首先,我們需要了解一些運算符。
>,<,<=,>=,=.<>(不等於)between......andin(集合)likeis nulland 或者 &&or 或 ||not 或 !我們要查詢這張學生表裡的內容:
查詢年齡大於20的學生:
select * from student1 where age>20;
查詢年齡大於等於20的人:
select * from student1 where age>=20;
依此類推,如果要查詢年齡小於或者小於等於或者等於多少歲,改變一下運算符和數字就好了。小編就不一一演示了。(注意等於寫一個等號就可以了)。
查詢年齡不等於20歲:
select * from student1 where age !=20;
也可以用這種方式:select * from student1 where age <> 20;
查詢結果:
查詢在年齡大於等於18,小於等於20之間的人:
方法1:select * from student1 where age>=18 && age<=20;
方法2:select * from student1 where age>=18 and age<=20;
方法3:select * from student1 where age between 18 and 20;
查詢年齡16,18,19的學生信息:
方法1:select * from student1 where age=16 or age=18 or age=19;
方法2:select * from student1 where age in(16,18,19);
查詢數學成績為null的學
生信息:select * from student1 where math is null;
結果為空,說明表裡的學生都有數學成績。
查詢數學成績不為空的學生信息:select * from student1 where math is not null;
關於MySQL中where的條件查詢,小編就先說到這裡,很簡單的條件查詢,只是where後面加條件,然後再簡單的翻譯一下英語,去理解就好了。希望這篇文章可以幫到大家,也歡迎各位小夥伴補充和糾錯。接下來的文章中小編會講模糊查詢(like)
關於MySQL小編講的比較跳,前期的一些基礎知識,小夥伴們需要自行去了解,小編在之後的文章中也會做相關補充。