1、增
insert?into?表 (列名,列名...)?values?(值,值,值...)
insert?into?表 (列名,列名...)?values?(值,值,值...),(值,值,值...)
insert?into?表 (列名,列名...)?select?(列名,列名...)?from?表
2、刪
delete?from?表
delete?from?表?where?id=1?and?name='alex'
3、改
update?表?set?name?=?'alex'?where?id>1
4、查
select?*?from?表
select?*?from?表?where?id > 1
select?nid,name,gender?as?gg?from?表?where?id > 1
5、其他
a、條件select * from 表 where id > 1 and name != 'alex' and num = 12;select * from 表 where id between 5 and 16;select * from 表 where id in (11,22,33)select * from 表 where id not in (11,22,33)select * from 表 where id in (select nid from 表)b、通配符select * from 表 where name like 'ale%' - ale開頭的所有(多個字符串)select * from 表 where name like 'ale_' - ale開頭的所有(一個字符)c、限制select * from 表 limit 5; - 前5行select * from 表 limit 4,5; - 從第4行開始的5行select * from 表 limit 5 offset 4 - 從第4行開始的5行d、排序select * from 表 order by 列 asc - 根據 “列” 從小到大排列select * from 表 order by 列 desc - 根據 “列” 從大到小排列select * from 表 order by 列1 desc,列2 asc - 根據 “列1” 從大到小排列,如果相同則按列2從小到大排序e、分組select num from 表 group by numselect num,nid from 表 group by num,nidselect num,nid from 表 where nid > 10 group by num,nid order nid descselect num,nid,count(*),sum(score),max(score),min(score) from 表 group by num,nidselect num from 表 group by num having max(id) > 10特別的:group by 必須在where之后,order by之前f、連表無對應關系則不顯示select A.num, A.name, B.namefrom A,BWhere A.nid = B.nid無對應關系則不顯示select A.num, A.name, B.namefrom A inner join Bon A.nid = B.nidA表所有顯示,如果B中無對應關系,則值為nullselect A.num, A.name, B.namefrom A left join Bon A.nid = B.nidB表所有顯示,如果B中無對應關系,則值為nullselect A.num, A.name, B.namefrom A right join Bon A.nid = B.nidg、組合組合,自動處理重合select nicknamefrom Aunionselect namefrom B組合,不處理重合select nicknamefrom Aunion allselect namefrom B
摘抄自:https://www.cnblogs.com/wupeiqi/articles/5713315.html