2017-02-25 1 views
0

私のユーザーテーブルを作業が、私はそれがために必要な0が、20行を表示する必要があり、使用、使用される顧客のdidnt sites.ifこれらのTOP20のための各顧客のための時間を必要とする列ハイブは

region,cust no,mobileno,null,host,null,usage,null,usageduration 
AP  404070620021081 Prepaid 919848052151 NULL Facebook  NULL 2.9384765625 NULL 1.726 
AP  404070620021081 Prepaid 919848052151 NULL HTTP NULL 1.0146484375 NULL 0.232 
AP  404070620021081 Prepaid 919848052151 NULL Bing NULL 8.8642578125 NULL 0.746 
AP  404070620021081 Prepaid 919848052151 NULL Crashlytics  NULL 19.4599609375 NULL 48.765 
AP  404070620021081 Prepaid 919848052151 NULL DNS  NULL 17.4296875  NULL 584.596 
AP  404070620021081 Prepaid 919848052151 NULL Doubleclick  NULL 6.908203125  NULL 1.362 
AP  404070620021081 Prepaid 919848052151 NULL Dropbox NULL 37.0380859375 NULL 42.174 
AP  404070620021081 Prepaid 919848052151 NULL Facebook  NULL 21.1533203125 NULL 29.689 
AP  404070620021081 Prepaid 919848052151 NULL Google NULL 49.0732421875 NULL 28.456 
AP  404070620021081 Prepaid 919848052151 NULL Google APIs  NULL 213.8642578125 NULL 49.866 
AP  404070620021081 Prepaid 919848052151 NULL Google Ads  NULL 5.7314453125 NULL 0.932 
AP  404070620021081 Prepaid 919848052151 NULL Google Calendar NULL 0.201171875  NULL 0.06 
AP  404070620021081 Prepaid 919848052151 NULL Google Cloud Messaging NULL 8.5419921875 NULL 143.50799999999998 
AP  404070620021081 Prepaid 919848052151 NULL Google Play  NULL 228.7880859375 NULL 88.77600000000001 
AP  404070620021081 Prepaid 919848052151 NULL HTTP NULL 0.29296875  NULL 1.16 
AP  404070620021081 Prepaid 919848052151 NULL NTP  NULL 0.1484375  NULL 0.122 
AP  404070620021081 Prepaid 919848052151 NULL SSL  NULL 96.095703125 NULL 452.88 
AP  404070620021081 Prepaid 919848052151 NULL Skype NULL 93.6953125  NULL 67.649 
AP  404070620021081 Prepaid 919848052151 NULL TCP  NULL 93.591796875 NULL 117.32900000000001 
AP  404070620021081 Prepaid 919848052151 NULL WhatsApp  NULL 165780.6171875 NULL 1097.055 
AP  404070620021081 Prepaid 919848052151 NULL XMPP NULL 62.4453125  NULL 350.03700000000003 


my top20 table contains host,rank 
SSL      1 
TCP      2 
DNS      3 
HTTP     4 
Facebook    5 
Google Play    6 
Google Cloud Messaging 7 
YouTube     8 
UDP      9 
XMPP     10 
Skype     11 
WhatsApp    12 
Bittorrent    13 
Google     14 
STUN     15 
Google APIs    16 
Doubleclick    17 
Apple     18 
MDNS     19 
Google Ads    20 

として、以下のデータが含まれていない参加左各顧客。私は左に参加しましたが、すべての組み合わせでgettin 420行をしました。間違っています。顧客ごとに20行を取得することをお勧めします。

答えて

0

cust_noとホストのすべての組み合わせを見つけるには、それと。

select t.cust_no, 
    t.host, 
    coalesce(u.usage, 0) usage, 
    coalesce(u.usageduration, 0) usageduration 
from (
    select * 
    from (
     select distinct cust_no 
     from user 
     ) u 
    cross join top20 t 
    ) t 
left join user u on t.cust_no = u.cust_no 
    and t.host = u.host; 
+0

で20件のレコードを必要とします –

0

こんにちは私は

SELECT 
    imsi, 
    msisdn,Subscription_plan, 
    cust_nationality, 
    application_name, 
    rank,is_app, 
    total_data_volume_host, 
    SUM(total_data_volume_app) AS total_data_volume_app, 
    event_duration_host, 
    SUM(event_duration_app) AS event_duration_app 
FROM (SELECT 
    ps_data.cust_nationality, 
    ps_data.imsi,ps_data.Subscription_plan, 
    ps_data.msisdn, 
    ps_data.host, 
    top20.host_app AS application_name, 
    top20.rank, 
    top20.is_app, 
    ps_data.total_data_volume_host, 
    ps_data.total_data_volume_app, 
    ps_data.event_duration_host, 
    ps_data.event_duration_app 
FROM (SELECT 
    circle, 
    host_app, 
    rank, 
    is_app 
FROM ps_top20_host_app_1_month 
WHERE is_app = '1') top20 
LEFT JOIN (SELECT 
    cust_nationality, 
    imsi,Subscription_plan, 
    msisdn, 
    NULL AS host, 
    application_name, 
    NULL AS total_data_volume_host, 
    SUM(COALESCE(total_data_volume,0))/1024 AS total_data_volume_app, 
    NULL AS event_duration_host, 
    SUM(COALESCE(data_transfer_time_dl, 0)/1000 + COALESCE(data_transfer_time_ul, 0)/1000) AS event_duration_app 
FROM ps_data_up_segg_1_day 
WHERE content_provider='1' and cust_nationality is not null and UPPER(cust_nationality) not in ('UNKNOWN','NULL IN SOURCE') and 
msisdn is not null and UPPER(msisdn) not in ('UNKNOWN','NULL IN SOURCE') AND dt >= '1487615400000'AND dt < '1487701800000' AND imsi='404070620021081' 
GROUP BY cust_nationality, 
     imsi, 
     msisdn,Subscription_plan, 
     host, 
     application_name) ps_data 
    ON (
    top20.circle = ps_data.cust_nationality) where (top20.host_app is not null and top20.host_app=ps_data.application_name))t2 
GROUP BY imsi, 
     msisdn,Subscription_plan, 
     cust_nationality, 
     host, 
     application_name, 
     rank,is_app, 
     total_data_volume_host, 
     event_duration_host 

以下のようにクエリを作成したが、共通しているだけで14行ない、すべての20 404070620021081 919848052151プリペイドAP DNS 3 1 NULL 17.4296875 NULL 584.596 404070620021081 919848052151プリペイドAPを取得していますダブルクリック17 1 NULL 6.908203125 NULL 1.362 404070620021081 919848052151プリペイドAP Facebook 5 1 NULL 24.091796875 NULL 31.415 404070620021081 919848052151プリペイドAP Google 14 1 NULL 49.0732421875 NULL 28.456 404070620021081 919848052151プリペイドAP Google APIの16 1 NULL 213.8642578125 NULL 49.866 404070620021081 919848052151プリペイドAP Googleの広告20 1 NULL 5.7314453125 NULL 0.932 404070620021081 919848052151プリペイドAP Googleクラウドメッセージング7 1 NULL 8.5419921875 NULL 143.50799999999998 404070620021081 919848052151プリペイドAP Googleは6 1 NULLを再生228.7880859375 NULL 88.77600000000001 404070620021081 919848052151前払いAP HTTP 4 1つのNULL 1.3076171875 NULL 1.392 404070620021081 919848052151前払いAPのSSL 1 NULL 96.095703125 NULL 452.88 404070620021081 919848052151前払いAPスカイプ11 1 NULL 93.6953125 NULL 67.649 404070620021081 919848052151前払いAP TCP 2 1 NULL 93.591796875 NULL 117.32900000000001 404070620021081 919848052151プリペイドAPのWhatsApp 12 1 NULL 165780.6171875 NULL 1097.055 404070620021081 919848052151プリペイドAP XMPP 10 1 NULL 62.4453125 NULL 350.03700000000003 しかしthiseユーザーのためにその間違ったが、私は、クエリを作成し、未使用のホスト0用法