多语言展示
当前在线:546今日阅读:103今日分享:49

MYSQL常用的基本语句

我们现在学习下几个基本的sql语句,万变不离其宗,把基础弄扎实了其它的就很容易了。希望能帮到你。
方法/步骤
1

选择:select * from table where 范围

2

插入:insert into table(field1,field2) values(value1,value2)

3

删除:delete from table where 范围

4

更新:update table set field1=value1 where 范围

5

查找:select * from table where field1 like ’%value1%’

6

排序:select * from table order by field1,field2 [desc]

7

总数:select count as totalcount from table

8

求和:select sum(field1) as sumvalue from table

9

平均:select avg(field1) as avgvalue from table

10

最大:select max(field1) as maxvalue from table

11

最小:select min(field1) as minvalue from table

12

例: SELECT TOP 20 * FROM table 意思是:从table中查询前 20 项的全部内容 *可以用table中的内容表示 意思是:从table中查询前 20 项'某一项'的内容 SELECT SUM(grade) as total,average(grade) as average  FROM table GROUP BY class 意思是:以班级为单位,查询这个班的总成绩和平均成绩 UPDATE table SET age=age+10 意思是:将 table 中所有人的年龄增加10岁

推荐信息