2017-02-25 6 views
0

meine Benutzertabelle folgende Daten als Spalten enthälthive LEFT JOIN nicht funktioniert

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 

ich brauche Nutzung, die Dauer für jeden Kunden für diese Kunden nur knapp sein Ziel sites.if top20 verwendet, dann sollte es zeigen 0, aber 20 Zeilen erforderlich für jeder Kunde. Ich mache linksbündig aber 420 Zeilen mit allen Kombination.Was ist falsch. bitte schlagen Sie 20 Zeilen für jeden Kunden

Antwort

0

Eine Möglichkeit ist, alle Kombinationen von cust_no und Host mit einem Cross-Join und dann Links Join Benutzer Tabelle zu finden damit.

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

i eine Abfrage erstellt –

0

Hallo habe ich eine Abfrage wie unten

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 

aber bin immer nur 14 Zeilen, die gemeinsam sind nicht alle 20 404070620021081 919848052151 Prepaid AP DNS 3 1 NULL 17,4296875 NULL 584,596 404070620021081 919848052151 Prepaid AP Doppelklick 17 1 NULL 6.908203125 NULL 1.362 404070620021081 919848052151 Prepaid AP Facebook 5 1 NULL 24.091796875 NULL 31.415 404070620021081 919848052151 Prepaid AP Google 14 1 NULL 49.0732421875 NULL 28.456 404070620021081 919848052151 Prepaid AP Google APIs 16 1 NULL 213,8642578125 NULL 49,866 404070620021081 919848052151 Prepaid AP Google-Anzeigen 20 1 NULL 5,7314453125 NULL 0.932 404070620021081 919848052151 Prepaid AP Google Cloud Messaging 7 1 NULL 8,5419921875 NULL 143,50799999999998 404070620021081 919848052151 Prepaid AP Google Play 6 1 NULL 228,7880859375 NULL 88,77600000000001 404070620021081 919848052151 Prepaid AP HTTP 4 1 NULL 1,3076171875 NULL 1,392 404070620021081 919.848.052.151 Prepaid SSL AP 1 1 NULL 96,095703125 NULL 452,88 404070620021081 919848052151 Prepaid AP Skype 11 1 NULL 93,6953125 NULL 67,649 404070620021081 919848052151 Prepaid AP TCP 2 1 NULL 93,591796875 NULL 117.32900000000001 404070620021081 919848052151 Prepaid AP WhatsApp 12 1 NULL 165.780,6171875 NULL 1097,055 404070620021081 919848052151 Prepaid AP XMPP 10 1 NULL 62,4453125 NULL 350,03700000000003 aber sein falsch für thise Benutzer ich brauche 20 Datensätze, bei denen nicht genutzte Rechner mit 0 Nutzung