select a.id,b.is_manager_big, b.is_manager_bcompany,a.one_shoukuan,a.two_shoukuan,b.one_income,b.two_income from (select a.id, SUM(CASE WHEN b.shoukuan_month = '2023-05' and b.is_del = 0 then b.netincome ELSE 0 end) as one_shoukuan, SUM(CASE WHEN b.shoukuan_month = '2023-04' AND b.is_del = 0 THEN b.netincome ELSE 0 END) as two_shoukuan from xw_kefu a left join xw_user_applyloan_checking b on b.kefuid = a.id where a.id in (1748,1749,1776,1834,1913,1921,1922,1778,1830,1829,1833,1835,1750,1753,1754,1756,1758,1761,1892,1905,1762,1764,1902,1915,1751,1773,1792,1774,1788,1917,1791,1793,1795,1909,1775,1787,1752,1757,1771,1772,1914,1768,1898,1760,1767,1769,1863,1770,1827) and a.is_del = 0 and a.is_lizhi = 0 group by a.id) as a,(select a.id,a.is_manager_big, a.is_manager_bcompany, SUM(CASE WHEN b.month = '2023-05' then b.create_income end) as one_income, SUM(CASE WHEN b.month = '2023-04' THEN b.create_income END) as two_income from xw_kefu a left join xw_kefu_performance_target b on b.kefuid = a.id where a.id in (1748,1749,1776,1834,1913,1921,1922,1778,1830,1829,1833,1835,1750,1753,1754,1756,1758,1761,1892,1905,1762,1764,1902,1915,1751,1773,1792,1774,1788,1917,1791,1793,1795,1909,1775,1787,1752,1757,1771,1772,1914,1768,1898,1760,1767,1769,1863,1770,1827) and a.is_del = 0 and a.is_lizhi = 0 group by a.id ) as b where b.id = a.id group by a.id优化一下这个查询统计
最新发布