วันจันทร์ที่ 1 ธันวาคม พ.ศ. 2557

SQL COUNT

SQL COUNT 
เป็นคำสั่งที่ใช้สำหรับการระบุเงื่อนไขการเลือกข้อมูลในตาราง (Table) โดยทำการนับจำนวน Count Record ที่ค้นพบ 

Database : MySQL,Microsoft Access,SQL Server,Oracle

Syntax

SELECT COUNT(Column/Field) AS [New-Field] FROM [Table-Name]


Table : customer
CustomerID
Name
Email
CountryCode
Budget
Used
C001
Win Weerachaiwin.weerachai@thaicreate.com
TH
1000000600000
C002
John Smithjohn.smith@thaicreate.com
EN
2000000800000
C003
Jame Bornjame.born@thaicreate.com
US
3000000600000
C004
Chalee Angelchalee.angel@thaicreate.com
US
4000000100000


Sample1 การเลือกข้อมูลจำนวนลูกค้าทั้งหมด

SELECT COUNT(CustomerID) AS CountCustomerID FROM customer

Output 

CountCustomerID
4

ไม่มีความคิดเห็น:

แสดงความคิดเห็น