SQL語句實戰——DML語句(重點)ide
選擇:select * from table1 where 範圍spa
插入:insert into table1(filed1,filed2)values (filed1,filed2)blog
解釋:filed1,filed2 字段名;filed1,filed2字段值排序
刪除:delete from table1 where 範圍it
更新:update table1 set field1=value1 where 範圍io
查找:select * from table1where filed1 like ‘%value1%’ table
解釋:查找包含value1的模糊匹配class
若是查找以value1開頭,則用‘value1%’;date
若是查找以value1結尾:則用‘%value1’;file
排序:select * from table1 order by filed1,filed2[desc]
解釋:[desc]倒敘 [asc]正序
總數:select count(*) as 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
實戰練習:
1) 插入
對persion_info插入四條數據:
語句:(person_id是自增加的,因此不用寫)
insert into person_info(name,country,salary)
values ( '小趙 ', 'China',1200.01),
('小錢 ', '上海 ',1600.32),
( '小孫 ', '廣州 ',2000.40),
( '小李 ', '珠海 ',1670.88);
執行結果:
2) 更新:
若是想把小趙的country字段換成北京,則執行語句:
update person_info set country = '北京' where name = '小趙';
執行後的結果以下:
3) 排序
對name進行order by排序
語句:select * from person_info order by name desc;
運行結果:
4) 查找
查找包含「趙」的模糊匹配數據,語句「」
Select * from person_info where name like ‘%趙%’;
運行結果:
5) 總數
求person_info表裏的數據總條數
語句:Select count(*) as totalcount from person_info;
執行結果:
可見結果是4,同時字段名爲totalcount。
6) 求和
語句:select sum(salary) as sumvalue from person_info;
執行結果: