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

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章