1. 程式人生 > >MySql:通過增加額外欄位,將不相關的結果集關聯起來

MySql:通過增加額外欄位,將不相關的結果集關聯起來

select sit as '區域', ordC as '訂單數', cusC as '客戶數' from ( select case bt1.cl when 1 then '西區' when 2 then '東區' when 3 then '南區' when 4 then '北區' end, bt1.c, bt2.c from ( select count
(*) as c, 1 as cl from order where ... UNION ALL select count(*) as c, 2 as cl from order where ... UNION ALL select count(*) as c, 3 as cl from order where ... UNION ALL select count(*) as c, 4 as cl from order where ... ) bt1 left join ( select
count(*) as c, 1 as cl from cust where ... UNION ALL select count(*) as c, 2 as cl from cust where ... UNION ALL select count(*) as c, 3 as cl from cust where ... UNION ALL select count(*) as c, 4 as cl from cust where ... ) bt2 on bt1.cl = bt2.cl )