1. 程式人生 > >group by 語句

group by 語句

pos 最小值 計算 min 例如 程序 avg pla 數值

user E_book
go
select sum(user),play from 表名 where name=6 這樣的程序會出錯,因為play沒有使用sum,所以要分組。
select sum(user),play 表名 where name=6 group by play
有函數的和沒有函數的表一起使用要用 GROUP BY
5.AVG 求平均值,只能與數值型一起使用 空值被忽略。
select avg(fitem) from 表名 where name=7
6.MAX和MIN,求最大最小值,空值被忽略 可以和數值、日期、字符一起使用
select MAX(nianling) as 年齡 from
表名 7.count 用於統計記錄中的記錄數,如果寫列名空值被忽略。 select count(*) from user  統計所有記錄數 select count (name) from user  統計用戶數 例如使用語句count函數來獲取employee表中的員工數量。 use book --指定數據庫 GO select count(employID) from employee GO 又如,下面的語句使用sum函數計算sales表中的銷售總額 USE book GO
select sum(linetotal)from sales GO

group by 語句