标签:select insert update delete count
SQL语句实战——DML语句(重点)选择:select * from table1 where 范围
插入:insert into table1(filed1,filed2)values (filed1,filed2)
解释:filed1,filed2 字段名;filed1,filed2字段值
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1where filed1 like ‘%value1%’
解释:查找包含value1的模糊匹配
如果查找以value1开头,则用‘value1%’;
如果查找以value1结尾:则用‘%value1’;
排序: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;
执行结果:
标签:select insert update delete count
原文地址:http://blog.51cto.com/1108944/2105460