2016-02-04 61 views
0

我有一個表與以下記錄:SQL計數來自同一列

BookingTimeStamp BookingReloc AEType 
2016-01-14 23:19:24.773 LVWCQL Seat 
2016-01-14 23:19:24.773 LVWCQL Seat 
2016-01-14 23:19:24.773 LVWCQL Seat 
2016-01-14 16:45:29.450 KCCEMG Baggage 
2016-01-14 16:34:07.117 MEZYPN Insurance 
2016-01-14 16:08:40.617 CJXDFK Insurance 
2016-01-14 16:08:40.617 CJXDFK Insurance 
2016-01-14 16:08:40.617 CJXDFK Insurance 
2016-01-14 16:08:40.617 CJXDFK Insurance 
2016-01-14 15:14:51.633 JMILRY Seat 

我想要計數值的重複列AEType。

所需的輸出:

Seat = 4 

Baggaage = 1 

Insurance =5 

是否有可能得到它在一個單一的查詢?

+2

查看'group by'。 –

回答

1

使用'group by'按不同的參數對sql條目進行分組,'count(*)'可用於統計每個不同AEType的sql條目數。

select AEType,count(*) from Table_Name group by AEType; 
1
select AEType,count(*) from table_name 
group by AEType;