標籤:
1.查詢資料
select 屬性列表
from 表名和視圖列表
[where 條件運算式1]
[group by 屬性名稱1 [having 條件運算式2] [with rollup最後加一條記錄是上面記錄的總和]] //按照屬性名稱1指定的欄位分組,有having則要滿足條件運算式2
[order by 屬性名稱2 [asc|desc]]
where查詢條件:
比較 =、<、<=、 >、>=、!=、<>、!>、!<
指定範圍 between and、not between and
指定集合 in、not in
匹配字元 like、not like <%:代表任意長度字串,_:代表單個字元>
是否為空白值 is null、is not null
eg:select * from test0 where id in (1001,1004,1005);
select * from test0 where id between 1002 and 1005;
select * from test0 where id < 1004 and name like ‘h_h_‘; //兩個條件均滿足
select * from test0 where id < 1004 or name like ‘h%‘; // 滿足其中一個便可
select distinct name from test0; //查詢結果不重複
select id,group_concat(name) from test0 group by name;//將name分組中指定欄位值都顯示出來
select name,count(name) from test0 group by name;//將name分組的每一組記錄數統計出來
select name,count(name) from test0 group by name having count(name) > 1; //顯示記錄數大於1的
having運算式是作用於分組後的記錄,而where作用於表或者視圖。
select name,count(name) from test0 group by name with rollup;
select * from test0 limit 3; //只顯示3條記錄
select * from test0 limit 1,3; //從第2條記錄起顯示3條記錄
MySQL基本操作-SQL查詢語句