mysql與其他編輯性語言類似通??梢該诫s各種算術(shù)運(yùn)算符,比較運(yùn)算符,邏輯運(yùn)算符 等運(yùn)算符 對(duì)數(shù)據(jù)進(jìn)行操作: 算術(shù)運(yùn)算符: select * from biao where eid%2=0; ?。ㄈ∮噙\(yùn)算符) select eid,basic_sarary/12 as "日新" from salary; ?。ǔǎ?nbsp; 加減乘
比較運(yùn)算符: #=,>, <,>=, <=, !=(不等于<>),<=>(安全等于)
SELECT eid,basic_salary FROM t_salary WHERE basic_salary <> 10000; #查詢basic_salary=10000,注意在Java中比較是== SELECT eid,basic_salary FROM t_salary WHERE basic_salary = 10000; #查詢commission_pct等于0.40 SELECT eid,commission_pct FROM t_salary WHERE commission_pct = 0.40; SELECT eid,commission_pct FROM t_salary WHERE commission_pct <=> 0.40; #查詢commission_pct等于NULL SELECT eid,commission_pct FROM t_salary WHERE commission_pct IS NULL; SELECT eid,commission_pct FROM t_salary WHERE commission_pct <=> NULL; #查詢commission_pct不等于NULL SELECT eid,commission_pct FROM t_salary WHERE commission_pct IS NOT NULL; SELECT eid,commission_pct FROM t_salary WHERE NOT commission_pct <=> NULL;
邏輯運(yùn)算符: #與&&,或||,非! #與 AND,或 OR ,非 NOT,異或 XOR select * from biao where gender="男" and birthday<"1990-01-01"; select * from biao where job_id=1 or job_id=2;
三種模糊查詢方式: select from employee where name like '%冰%'; #查詢名字帶有冰的名字 select from emplyee where name like '李%'; #查詢名字中李姓的名字 select from emplyee where name like '李_'; #查詢名字中李姓的名字(名字為單字)
范圍和集合: select eid,basic_salary from t_salary where basic_salary between 9000 and 12000; 查詢eid 是 1,3,5基本工資
null值判斷與計(jì)算處理 select eid,commiss from t_salary where commiss is not null;
select eid,commiss from t_salary where commiss ifnull (value1,value2); 如果value1不為空,返回value1;否則返回value2
編碼格式 show variables like 'character_set_database'; 查看數(shù)據(jù)庫(kù)編碼格式 show create table<表名>; 查看數(shù)據(jù)表的編碼格式
去重關(guān)鍵字 (distinct) select distinct id from employee; 查詢員工的編號(hào) select count(distinct id) from employee; 統(tǒng)計(jì)員工表中有幾個(gè)部門
select 的五個(gè)句子 (1):where 按條件查詢 where后面接條件 (2):group by 分組 group by 后面接字段名 或者條件 (3):having 篩選 having 后面接條件 (4):order by 排序 order by 后面接字段名 或者條件 (5):limit 分頁(yè) limit m,n m表示從下標(biāo)為m的記錄開始查詢,第一條記錄下標(biāo)為0,n表示取出n條出來,如果從m開始不夠n條了,就有幾條取幾條。
|
|