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;
执行结果: