数据库常用语句

一下介绍的是sql数据库的常用语句,很多类型的数据库都可以使用sql语句,差别不大,这里以sql数据库为主,

选择:

      select * from table1 where 范围;//选择数据库表table1中此范围的数据

插入:

      insert into table1(field1, field2) values (value1, value2);//向table1中的列field1、field2中分别插入value1和value2.

删除:

     delete from table1 where 范围;//删除数据库表table1中此范围的数据

更新:

    update table1 set field1 = value1, filed2 = value2 where 范围;//将表table1中此范围的列field1和field2 的数据改为value1和value2.

查找:

    select * from table1 where field1 like '%value1%';//查找表table1中filed1为value1的值

排序:

    select * from table1 order by field1, filed2 [desc];//将表table1中的列field1和field2按照降序排列,desc为降序,asc为升序

总数:

    select count as totalcount from table1;//将表table1中的所有数据相加求出总和作为新列totalcount的值

求和:

    select sum(field1) as sumvalue from table1;//将表table1中列field1的值相加求出总和作为新列totalcount的值

平均:

    select avg(field1) as avgvalue from table1;//将表table1中列field1所有值的平均值求出作为新列totalcount的值

最大:

    select max(field1) as maxvalue from table1;//求出表table1中列field1的最大值给maxvalue

最小:

    select min(field1) as minvalue from table1;//求出表table1中列field1的最小值给minvalue。

posted on 2015-10-15 16:54  !!-阳光-!!  阅读(279)  评论(0编辑  收藏  举报

导航