sql統計語句
sql語言誕生有一段時間了,里面有一些自帶的很方便的函數,對于操作數據庫來說是非常方便的,下面就介紹幾種統計。
1、統計記錄數 count函數,可以統計出這條sql會查詢出多少條記錄很多人用count(*),但建議用count(1)。 2、求合函數 sum,select SUM(num) from tmp_p,對表中 num列進行求合。
3、求平均值,select AVG(num) from tmp_p,對表中 sum列進行求平均值。 4、取出最大值,select MAX(num) from tmp_P,取出num列中最大的一個。
5、取出最小值,select MIN(num) from tmp_P,取出,num列中最小的一個。 6、將數值型數據轉換成字符型,select CONVERT(varchar(10),num) from tmp_p,該函數屬于sql server的函數,其它數據庫可參考相關資料。
。
SQL語句 查詢 統計
* * from 學生表* 學號,姓名,年齡 from 學生表* 學號,姓名,年齡 from 學生表 where 年齡 between 18 and 20 and 系別='IS'* 學號,姓名,年齡 from 學生表 where 姓名 like '李%' or 姓名 like '李%'5 select distinct 學號 from 學生表 where 成績 <606. select 姓名,年齡,系名 from 學生表 where 系 in ('IS','CS') order by 系名 ASC,姓名 desc7 select count(*) from 學生表 where 系= 'IS'8 select count(*) ,max(分數),min(分數)from 學生表 9 select 課程號,count(*),avg(分數) from 學生表 group by課程號10 select 學號,count(*) from 學生表 11 select avg(分數),課程號 from 學生表 group by 課程號12 select avg(分數),課程號 from 學生表 group by 課程號 order by avg(分數)13 select count(*),學號 from 學生表 group by 學號14 select count(*)a,學號 from 學生表 group by 學號 order by a15 select 課程名稱,avg(分數) from 學生表 group by 課程名16 select 課程標號,課程名稱,avg(分數) from 學生表 group by 課程號,課程名17 select 課程名稱,avg(分數)a from 學生表 where a >7018 select 姓名,count(*) a from 學生表 group by 姓名19 select 學號,姓名,count(*) a from 學生表 group by 學號,姓名20select 學生姓名,count(*) a from 學生表 where a> 4 group by 學生姓名。
SQL語句 查詢 統計
* * from 學生表
* 學號,姓名,年齡 from 學生表
* 學號,姓名,年齡 from 學生表 where 年齡 between 18 and 20 and 系別='IS'
* 學號,姓名,年齡 from 學生表 where 姓名 like '李%' or 姓名 like '李%'
5 select distinct 學號 from 學生表 where 成績 6. select 姓名,年齡,系名 from 學生表 where 系 in ('IS','CS') order by 系名 ASC,姓名 desc
7 select count(*) from 學生表 where 系= 'IS'
8 select count(*) ,max(分數),min(分數)from 學生表
9 select 課程號,count(*),avg(分數) from 學生表 group by課程號
10 select 學號,count(*) from 學生表
11 select avg(分數),課程號 from 學生表 group by 課程號
12 select avg(分數),課程號 from 學生表 group by 課程號 order by avg(分數)
13 select count(*),學號 from 學生表 group by 學號
14 select count(*)a,學號 from 學生表 group by 學號 order by a
15 select 課程名稱,avg(分數) from 學生表 group by 課程名
16 select 課程標號,課程名稱,avg(分數) from 學生表 group by 課程號,課程名
17 select 課程名稱,avg(分數)a from 學生表 where a >70
18 select 姓名,count(*) a from 學生表 group by 姓名
19 select 學號,姓名,count(*) a from 學生表 group by 學號,姓名
20select 學生姓名,count(*) a from 學生表 where a>4 group by 學生姓名