首页>>学生风采>>山东海天软件工程学院高传宝>>观点>>SQL SEVER 数据库复习资料(一)

SQL SEVER 数据库复习资料(一)

作者:高传宝
日期:2011/11/4 9:45:48

内容:
一、简单查询
1、查询所有数据,查询部分列数据,列别名
   select * from   表名
   select 列名1 as  "biaoti" ,"biaoti"=列名2 from   表名

2、查询不重复的数据,
   select distinct 列名1 as  "biaoti" ,"biaoti"=列名2 from   表名
  
3、查询前n行数据
   select   top n perent 列名1  ,列名2 from   表名
4、过滤行 
    运算符:比较运算符、逻辑运算符(and/or/not)、范围运算符([not]between  and )、列表运算符(in (zhi liebiao))、
    模式匹配符 : where  列名1 like  "%_[0-9][^0-9][ABC]" 
    null值判断符:  is null/is not null
   select   列名1  ,列名2 from   表名 where
             
5、排序
     select   列名1  ,列名2 from   表名 where
      order by 列名1 asc/desc ,列名2  asc/desc
   
二、函数
1、字符串函数:substring(expression,start,length)、--
       str(float_expression,[length,[decimal]])--

2、日期函数:getdate()、dateadd(datepart,number,date)、
     Datediff(datepart,date1,date2)、
     Year(date)、Month(date)、Day(date)

3、数学函数:round(numeric_exp,length)

4、转换函数:convert(datatype [(length)],expression[,style])

5、次序函数:row_number()、Rank()、dense_rank()
     
6、Isnull函数  isnull(列名1,值)
7、集合函数:min(列名1),max,sum,avg,count
   // select min(列名1),name from student
          
三、分组
 分组过滤
select min(列名1),列名1 from 表名 where
group by  列名1
having
 
四、连接
1、内连接
   select a.列名,b.列名2 from 表1  a 
    [inner] join 表2  b on a.列名=b.列名

2、外连接:左外连接、右外连接、全外连接
    select a.列名,b.列名2 from 表1  a 
    left|right|full [outer] join 表2  b on a.列名=b.列名
五、子查询
  select 列名1,列名2  from 表1
  where 列  运算符 (select 语句)
 
  select 列名1,列名2  from 表1
  where [not] exists(select 语句)
 
 [not] in
 [not] exists

http://abc.wm23.com/gaochuanbao   高传宝个人主页
http://weibo.com/1945453744
   高传宝新浪微博
http://blog.sina.com.cn/gaochuanbao123
   高传宝新浪博客

分享