黑马程序员技术交流社区

标题: 常用SQL语句总结 [打印本页]

作者: 孔健    时间: 2013-3-9 13:26
标题: 常用SQL语句总结
1、新建表create table
create table Person3(Number varchar(20),Age int)
2、数据插入insert into
insert into Person3(number,name) values('IT001','小明')
3、数据更新(修改)update set
update Person3 set age=30
4、数据检索select
select * from Person3
select number as 编号,NAME as 姓名,Salary+10000 as 月薪from Person3;-- as 用来给列名起别名
5、聚合函数
count()、max()、min()、avg()、sum()
6、数据排序order by
select * from Person3
where age>25 and age<=30
order by age ASC;  --注:order by 子句要放在where 子句之后
7通配符过滤'_', '%'
select * from Person3 where name like'_erry'  --检索以任意字符开,剩余部分为"erry"的数据
select * from Person3 where name like'%n%' --检索name中包含字n
8空值处理isnull/ is not null
select * from Person3
where name is not null --is not null 判断name不为null的数据
9多值匹配 in
select * from Person3
where age in(27,28,35)  --age 为27或28或35的
10数据分组group by
select age,avg(salary) from Person3
group by age   --根据age进行分组
11Having子句
select age,count(*)as 人数from person3
group by age
having count(*)>1 --having必须放在group by之后having只能对分组后的数据进行过滤

作者: 许庭洲    时间: 2013-3-9 22:25
值得学习ing!
作者: 李贤贤    时间: 2013-3-9 22:42
{:soso_e142:}
作者: 穆爱明    时间: 2013-7-7 08:23
了解一下,有备无患!




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2