1、經常使用的sql語句sql
一、建表語句排序
create table tabname(colname1 type1 [not null][primary key], colname2 type2,...)it
根據已有的表建立新表io
A:create table tab_new like tab_oldtable
B:create table tab_new asselect colname1,colname2... from tab_old definition onlyobject
二、刪除表date
drop table tabnameselect
三、增長一列sql語句
alter table tabname add column type DEFAULT '' COMMENT '***'語法
四、經常使用的基本的sql
選擇:select * from table1 where 範圍
插入:insert into table1(field1,field2) values (value1,value2)
刪除:delete from table1 where 範圍
更新:update table1 set field1=value1 where 範圍
查找:select * from table1 where field1 like ’%value1%’ ---like的語法很精妙,查資料!
排序:select * from table1 orderby field1,field2 [desc]
總數:select countas totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
2、提高
一、replace
select replace(object,'old_text','new_text')
update table set name=replace(name,'aa',bb') where name like '%查找的內容%'