select name from student where name='張三' ## 查詢name等于張三的數據 select name from student where name!='張三' ## 查詢name不等于張三的數據 select name from student where age>20 ## 查詢age大于20的數據 2、邏輯運算符
and
or
not
例子如下
select * from student where age>10 and name='張三' ##查詢age大于10且name等于"張三"的數據。 select * from student where not name='張三' ##查詢name不等于"張三"的數據。 3、范圍查詢
in
between 大數值 and 小數值
例子如下
select * from student where age in (10,11) ##查詢age等于10或者11的數據。 select * from student where age=10 or age=11 ## 與上面語句等效。 select * from student where age between 10 and 24 ##查詢age在10到24之間的數據,包含邊界值。 4、空判斷
select * from student where address is null ##查詢address為null的數據 select * from student where address is not null ##查詢address不為null的數據 5、模糊查詢
like
%表示任意多個字符(包括0)
_表示任意一個字符
escape:取消%或_字符的通配符特性
例子如下
select * from student where name like '王%' ##查詢name中姓張的數據。 select * from student where name like '張_ ##查詢name中兩個字姓張的數據。 select * from student where name like '%A%%' escape 'A' ##查詢name中含有"%"的數據 以上是“mysql如何查詢指定條件”這篇文章的所有內容,感謝各位的閱讀!