Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.1 kB
1
Indexable
Never
DROP TABLE IF EXISTS #dealer_MO_KP_modified
SELECT
    transaction_date,
    agent_inn_dil,
    client_inn_dil,
    client_name_dil,
    client_name_GZPN,
    SUM(total_monthly_ton_dil) AS total_monthly_ton_dil,
    SUM(CASE WHEN ((label = 'dil_MO') OR (label = 'dil_MO+KP' AND source_table = 'MO')) THEN total_monthly_ton_GZPN ELSE 0 END) AS MO_dealer_monthly_ton_GZPN,
    SUM(CASE WHEN ((label = 'dil_KP') OR (label = 'dil_MO+KP' AND source_table = 'KP')) THEN total_monthly_ton_GZPN ELSE 0 END) AS KP_dealer_monthly_ton_GZPN,
    --SUM(CASE WHEN label = 'dil_MO+KP' AND source_table = 'MO' THEN total_monthly_ton_GZPN ELSE 0 END) AS MO_KP_dealer_monthly_ton,
    --SUM(CASE WHEN label = 'dil_MO+KP' AND source_table = 'KP' THEN total_monthly_ton_GZPN ELSE 0 END) AS KP_MO_dealer_monthly_ton,
    okved_client,
    label
INTO #dealer_MO_KP_modified
FROM #dealer_MO_KP
--WHERE client_name_dil like('%гладков%')
GROUP BY transaction_date, agent_inn_dil, client_inn_dil, client_name_dil, client_name_GZPN, okved_client, label--, source_table
ORDER BY client_inn_dil, transaction_date;
Leave a Comment