目錄
select
查詢列表
from
表名where
篩選表示式;
條件運算子:>,,>=,<=
條件運算子不能判斷null。
#在employees表中篩選工資大於12000的員工的所有資訊
select
*from
employees
where
salary>12000;
邏輯運算子:&&,||,!,and,or,not
用於連線條件表示式
select
*from
e程式設計客棧mployees
where
salary>12000 and salary<16000;
關鍵字:like,between and,in,is null,is not null
①like:通常和萬用字元搭配使用
萬用字元:%表示任意個任意字元,_表示乙個任意字元
如果需要用到萬用字元本身,則使用\轉義符,如\_。
#查詢名字第二個字www.cppcns.com母為a的員工的所有資訊
select
*f程式設計客棧rom
employees
where
last_name like '_a%';
②between and:包含兩個臨界值,注意兩個臨界值順序不能顛倒
select
*from
employees
where
salary between 10000 and 16000;
③in:判斷某字段的值程式設計客棧是否屬於in列表中的某一項,不支援萬用字元
#查詢工作編號為sa_man,pr_rep的員工的所有資訊
select
*from
employees
where
job_id in('sa_man','pr_rep');
④is null(is not null):為空和不為空
#查詢沒有獎金的員工的所有資訊
select
*from
employees
where
commission_pct is null;jloegmon
符號:<=>表示等於,可以替代is,=
select
*from
employees
where
commission_pct <=> null;
資料庫mysql基礎查詢之條件查詢
有時候,我們想查詢出特定條件的資料,那該如何查詢呢?答案是使用where關鍵字 我們還是以如下的表為例 where關鍵字後面可以新增條件表示式。舉例子 上表中,我們要查詢出last name為 k ing的資料 select from employeeswhere last name k ing 通...
mysql分頁和條件查詢 資料庫 條件查詢和分頁
productdao dao newproductdao 目的 就是想辦法封裝乙個pagebean 並返回 pagebean pagebean newpagebean 1 當前頁private int currentpage pagebean.setcurrentpage currentpage 2...
Python資料庫查詢之組合條件查詢 F Q查詢
f查詢 取字段的值 關於查詢我們知道有 filter values get exclude 如果是聚合分組,還會用到aggregate和annotate,甚至還有萬能的雙下劃線,但是如果有這樣乙個需求,查詢a表中的aa欄位數值大於b表中bb欄位數值,應該怎麼做呢,django提供乙個f表示式來支援這...