SQL SERVER2005 第三讲

 

Select查询

Use test

Go

Select * from tablename

Go

 

Select s_nameage from tablename

Select ‘姓名’=s_nameage‘年龄’,sex as‘性别’,addess from tablename

Where sex=‘男’and age>25

Go

 

Select ‘姓名’=s_nameage‘年龄’,sex as‘性别’,addess from tablename

Order by age desc(降序排序)

 

Select top 1‘姓名’=s_nameage‘年龄’,sex as‘性别’,addess from tablename

Order by age desc

Go

 

模糊查找

Select ‘姓名’=s_nameage‘年龄’,sex as‘性别’,addess from tablename

Where s_name like’%’ (任意值)

Where s_name like’_’ (两个字符的任意值)

 

“或”

Select ‘姓名’=s_nameage‘年龄’,sex as‘性别’,addess from tablename

Where s_name like ‘[张小]%’(查找姓张或者性小的)

Where s_name like ‘[^张小]%’(查找出了查找姓张或者性小的)

函数

1,聚合函数

Select count(*) from tablename

2,字符串函数
select getdate()

3,日期函数

Select datename(d,getdate())

Select datepart(d,getdate())

 

数学函数

 

总结

T-sql语句

Select

函数