在子查詢s
下面計算消費者總數和操作系統計數。由於使用了分析函數,因此行數保持與源數據集中的相同。這就是爲什麼你需要通過consumer_id和operating_system進行聚合。使用max
或min
:
select --group by consumer_id and operating_system
customer_id,
operating_system,
max(operating_system_cnt) operating_system_cnt,
max(total_cnt) total_cnt,
max(operating_system_cnt)*100/max(total_cnt) operating_system_percent
from
(
select --calculate total count and operating_system_count
customer_id,
operating_system,
count(transaction_id) over(partition by customer_id, operating_system) operating_system_cnt,
count(transaction_id) over(partition by customer_id) total_cnt
from your_table
where --your filter conditions here for mobile/tablet and last 360 days
)s
group by
customer_id,
operating_system
以下是我準備的查詢。我不知道天氣它會不會起作用。選擇t.customer_id,t.operating_system,100 *(count(t.transaction_id)/ q1.total) 從 表t, (選擇count(transaction_id)作爲表中的總數,其中device_type在(mobile,tablet)和transaction_time 360 集團通過CUSTOMER_ID )Q1 凡 DEVICE_TYPE在(手機,平板電腦),並通過CUSTOMER_ID transaction_time 360 集團,OPERATING_SYSTEM –