mysql多表统计

SELECT
g.*
FROM
    (
    SELECT
    SUM( IF ( a.`status` = 'xcasd' OR a.`status` = 'safasf' OR a.`status` = 'd进' OR t.`status` = "dfsdf", 1, 0 ) ) AS kj_conversion,
    SUM( IF ( b.`type` = '士大夫', 1, 0 ) ) AS kj_total,
    SUM( IF ( b.`type` = '手掌机', 1, 0 ) ) AS hm_total,
    SUM( IF ( b.`type` = '啊实打实的', 1, 0 ) ) AS ai_total,
    SUM( IF ( b.`type` = 'z'x'c'z'x'c', 1, 0 ) ) AS ka_total,
    c.*
    FROM
        cacrm_ca_crm_user AS c
        RIGHT JOIN ox_afsafn_pro AS b ON c.id = b.bottom_level 
        OR c.id = b.four_level 
        OR c.id = b.three_level 
        OR c.id = b.two_level 
        OR c.id = b.one_level
        RIGHT JOIN ox_asdasd AS a ON b.user_id = a.user_id 
        AND a.bottom_level = b.bottom_level 
        AND a.is_delete = 0
        RIGHT JOIN cacrm_ca_crm_card_asfasdast t ON t.bottom_level = b.bottom_level 
    WHERE
        c.company = "asdzxcz" 
    GROUP BY
        b.user_id,
        b.type,
    b.bottom_level 
    ) AS g

你可能感兴趣的:(mysql)