SQL COUNT() 函數教程
COUNT( )函數返回的行數符合規定的標准。
數據庫計數( column_name )語法
COUNT( column_name )函數返回的數量值(空值將不予以計算)的指定欄:
SELECT COUNT(column_name) FROM table_name
數據庫計數COUNT( * )語法
COUNT( * )函數返回的記錄數量在一個表:SELECT COUNT(*) FROM table_nameSQL COUNT(DISTINCT column_name) Syntax
The COUNT(DISTINCT column_name
SELECT COUNT(DISTINCT column_name) FROM table_name來看個實例吧._Id OrderDate OrderPrice Customer 12008/11/121000Hansen22008/10/231600Nilsen32008/09/02700Hansen42008/09/03300Hansen52008/08/302000Jensen62008/10/04100Nilsen現在,我們要計數的訂單數量從“客戶尼爾森” 。
我們使用下面的SQL語句:
SELECT COUNT(Customer) AS CustomerNilsen FROM Orders WHERE Customer='Nilsen'結果SQL語句將上述2 ,因為客戶尼爾森取得了第2訂單總數:
CustomerNilsen 2
來看個SQL COUNT(*) 實例.
SELECT COUNT(*) AS NumberOfOrders FROM Orders輸出結果.NumberOfOrders 6SQL COUNT(DISTINCT column_name) 實例.現在,我們要計數的一些獨特的客戶在“訂單”表。
我們使用下面的SQL語句:
SELECT COUNT(DISTINCT Customer) AS NumberOfCustomers FROM Orders結果.NumberOfCustomers 3