English | 正體中文 | 简体中文

SQL count


范例资料表 : Orders (以下范例皆用此表当作资料来源)
Keyid OrderNo CustomerName SalePrice Quantity OrderDate
1 20101213095 John 3500 10 2010-12-13
2 20100620135 Jimmy 2509 22 2010-06-20
3 20100620392 Vincent 7200 5 2010-06-20
4 20100530006 Tyler 9200 50 2010-05-30
5 20100515129 Alan 100 50 2010-05-29
6 20100509059 John 2000 15 2010-05-09
7 20100503088 Alan 2200 17 2010-05-03


Example
计算有多少列的资料

Sytax : SELECT COUNT(column_name or *) FROM table_name
SQL
SELECT COUNT(*) FROM Orders

会输出结果
Count(*)
7

SQL
SELECT COUNT(Quantity) AS qtn FROM Orders WHERE Quantity = 50 

会输出结果
qtn
2

© 2012 PureExample.com contact