标签:
elect * from Fruit
添加
insert into Fruit values(‘K008‘,‘柿子‘,3.0,‘山西‘,90,‘‘)
insert into Fruit values(‘K009‘,‘火龙果‘,5.0,‘福建‘,110,‘‘)
insert into Fruit(Ids,Name,Price,Source,Numbers) values(‘K010‘,‘苹果‘,3.0,‘高青‘,90)
查询
select distinct Numbers from Fruit --查指定行 (去重显示)
select * from News --模糊查询
select * from News where title like ‘%贷款%‘ --查包含
select * from News where title like ‘%现代_‘ --_后面只能有一个字符
排序
select * from Fruit order by Numbers asc --不加asc默认升序排列,desc代表降序
select * from Fruit order by Numbers ,Price asc -- 先按前面的排一遍,在用后面的排一遍
select COUNT (1) from Fruit --返回表里有多少条数据 括号内*代表全部,写1节省运算量
select AVG (Numbers) from Fruit --所选列平均值
select SUM (Numbers) from Fruit --所选列总值
select MAX (Numbers) from Fruit --所选列最大值
select MIN (Numbers) from Fruit --所选列最小值
select*,(Price*0.8) as‘折后价格‘from Fruit --添加一列,八折价格,as可以省略
分组查询
select COUNT (Numbers) from Fruit group by Numbers -- 求该组成员个数
select Numbers,COUNT(*) from Fruit group by Numbers having COUNT(*)>1 -- 筛选大于1的
修改
update Fruit set Source=‘栖霞‘ where Ids=‘K001‘
删除
delete from Fruit where Ids=‘K010‘
delete from Fruit where Source=‘高青‘ -- 删除一整行
如果误删除,可恢复
事务:出现了错误,可以进行回滚
加事务:begin tran
回滚:rollback
begin tran
delete from Fruit where Ids=‘K010‘
rollback
标签:
原文地址:http://www.cnblogs.com/L6KE/p/4652578.html