sql语法,可能你会用到的

sql语法,也许你会用到的

   1、返回20%的数据

Select top 20 percent  *  from students  

 

 2、

   Sum 总数 :select sum(score) from students   计算学生的总分

   Avg 平均值:select avg(score) from students   计算学生的平均分

   Max 最大值:select Max(score) from students  计算学生的最高分

   Min 最小值:select Min (score) from students   计算学生的最低分

 

   3、查询奇数列和偶数列汇总

     Select sum(A)  from students where ID%2 <> 0

      Select sum(A)  from students where ID%2 = 0

 

4、随机取出5条数据 newid()这个函数总是能返回一个新的GUID号码

Select top 5 *  from students order by newid()

 

5、删除重复列的数据  distinct

   select distinct year(createdate) from students

 

6、统计一个数据库中有多少张表

  select count(*) from sysobjects where xtype='U'

 

7、列出数据库里所有的表名

select name from sysobjects where type='U'

 

8、查看硬盘分区

  EXEC master..xp_fixeddrives