2013-12-23 35 views
0

我們使用配置單元在AB測試數據上運行查詢。這裏的問題是我們有一些重複的數據,我們試圖忽略。幸運的是,我們有辦法忽略重複的數據。我們的conversion_meta列包含此重複數據的指標。基於一對不同的值計算行

我想找distinct (conversion_meta, conversion_type)。我無法真正弄清楚正確的語法。以下是我迄今爲止:

select conversion_type, day, sum(if(is_control='true', 1, 0)) as Control, 
sum(if(is_control='false', 1, 0)) as Test from Actions 
where day > "2013-12-20" and experiment_key='xyz' group by conversion_type, day 

在最終結果中的列應該是這樣的:

轉換類型,日,控制(計數),測試(計數)

+0

conversion_meta如何工作? – PeterRing

+0

@PeterRing它只是一個json blob,但它基本上有1個關鍵在這種情況下。在這種情況下,它只包含一個訂單ID。如果訂單ID對於單個轉換類型出現多次,那麼它是重複的。如果有一種方法可以只計算不同的元類型和轉換類型,並將它們按照理想的日期分組。 – Parris

回答

0

我想你可以通過工會全部解決此問題。:

select conversion_type, day, sum(if(is_control='true', 1, 0)) as Control, 
sum(if(is_control='false', 1, 0)) as Test from Actions 
where day > "2013-12-20" and experiment_key='xyz' and conversion_meta = false 
group by conversion_type, day 
UNION ALL 
select conversion_type, day, sum(if(is_control='true', 1, 0)) as Control, 
sum(if(is_control='false', 1, 0)) as Test from Actions 
where day > "2013-12-20" and experiment_key='xyz' and conversion_meta = true 
group by conversion_type, day 
+0

Hmm well conversion_meta不是true/false它是一個帶有訂單ID的json blob。這是唯一的東西。 Soooo有沒有一種很好的方法來查找不同的conversion_meta/conversion_type並在一天之內對它們進行計數? – Parris