我已在Vertica的數據庫SQL:獲取頻率計數器,類似透視表
+---------+-------+
| ReadOut | Event |
+---------+-------+
| 1 | A |
| 1 | A |
| 1 | B |
| 1 | B |
| 2 | A |
| 2 | B |
| 2 | B |
+---------+-------+
下表我試圖讓每個事件的頻率,每讀出。也許我missusing在這種情況下,術語「頻率」,但最好在最後我會像這樣的表:
+-----------+---------+---------+--+
| Frequency | Event_A | Event_B | |
+-----------+---------+---------+--+
| 1 | 1 | 0 | |
| 2 | 1 | 2 | |
| 3 | 0 | 0 | |
| 4 | 0 | 0 | |
| . | 0 | 0 | |
| . | 0 | 0 | |
| . | 0 | 0 | |
+-----------+---------+---------+--+
到目前爲止,我實現了一個在Python中循環,看起來像這樣(簡體版) :
# get all the available event names
Eventlist=SELECT DISTINCT Event FROM table
# loop over each event to get the frequency
for ii in Eventlist:
SELECT count(Readout) FROM table WHERE Event = ii group by Readout
但disadvante是,我需要提前知道的事件,需要一個單獨的查詢的名字,我必須跑一堆循環。 有沒有更好的方法來做到這一點。 Thanks Mates
你錯過了一個序列/時間戳列 –
@DuduMarkovitz你能否詳細說明一下? – valenzio
對不起,我的壞......... –