黑马程序员_.NET学习11(书第四章)

来源:互联网 发布:xlplayer mac有杂音 编辑:程序博客网 时间:2024/05/19 04:25

---------------------- Windows Phone 7手机开发.Net培训、.NET学习型技术博客、期待与您交流! ----------------------


--查询语句  在shuben数据库
select [Name],[Age],[Sex] from  Teacher

--使用DISTINCT避免重复信息
--语法
--Select distinnct column FROM table_source

--查询所有列
select * from teacher

--单列排序
--所谓单列排序是按照某一列的顺序(升序或降序)进行排列显示的。即order by 子句后面只有一个字段  
--语法  select col1, col2,......from table_name order by coln
--示例
select [no],[name],[sex] from teacher order by[no] desc

--多列排序
--示例
select [no],[name],[sex] from teacher order by[sex],[age] desc

--采用序号进行多列排序
--示例
select [no],[name],[sex] from teacher order by 3,2 desc
--order by 后面的序号3,2分别对应的是性别和姓名

--where子句单条件查询
select [no],[name],[sex],[salary],[department],[age] from teacher where [name]='李连杰'

select [no],[name],[sex],[salary],[department],[age] from teacher where [sex]='男'

--查询年龄大于等于40岁的教师的姓名,年龄,所在系等信息
select [name],[age],[department] from teacher where[age]>=40

--查询非体育系的所有教师的姓名,年龄,所在系等信息
select [name],[age],[department] from teacher where [department]<>'体育系'
select [name],[age],[department] from teacher where [department]!='体育系'

--between运算符范围筛选
--在where子句中,可以采用between运算符在两个值之间进行比较筛选。
--示例 查询年龄在工资在5000~9000的教师姓名,性别,工资
select [name],[sex],[salary] from teacher where [salary] between 5000 and 9000

NULL值的判断
所谓null值表示不知道(unknow)的数据,有三种可能:一,知道数据存在,但不知道具体的值,二,不知道数据是否存在;三,数据不存在。在实际查询中,经常遇到null值的操作。在SQL2005中,有关null值的运算符为is[NOT]NULL,用于判断数值是否为null。

示例
--查询工资不为空的教师姓名,性别,工资
select [name],[sex],[salary] from teacher where [salary] is not null

判断列中的值是否为null,只通过 is not null运算符,不可以写成“[salary]<>null”或者“[salary]!=null”或者“[salary]=null”。


---------------------- Windows Phone 7手机开发.Net培训、.NET学习型技术博客、期待与您交流! ----------------------

 

 

详细请查看:http://net.itheima.com/