大的方面 為 select ... from (查詢表) a where ... group by .... order by ..... 查詢表 為 將兩個表union , union時, 兩張表查詢出來的欄位名 必須是一致的, 沒有的欄位, 可以用 “ 0 as column ” 來補充。 1 ...
( SELECT sum( a.cost_sum ) AS sum_cost, sum( a.phone_sum ) AS sum_phone, sum( a.arrive_sum ) AS sum_arrive, FORMAT( sum( a.cost_sum ) / sum( a.arrive_sum ), 0 ) AS arrive_cb, a.time AS time FROM ( SELECT FROM_UNIXTIME( time, "%Y-%m-%d" ) AS time, sum( cost ) AS cost_sum, sum( arrive_true ) AS arrive_sum, sum( phone ) AS phone_sum FROM `cmf_test_jj_data` GROUP BY `time` UNION ( SELECT FROM_UNIXTIME( time, "%Y-%m-%d" ) AS time, 0 AS cost_sum, sum( arrive_num ) AS arrive_sum, 0 AS phone_sum FROM cmf_test_jj_arrive_new GROUP BY time ) ) a WHERE ( `a`.`time` >= 0 AND `a`.`time` <= 1551801600 ) GROUP BY a.time ORDER BY a.time DESC )
大的方面 為 select ... from (查詢表) a where ... group by .... order by .....
查詢表 為 將兩個表union , union時, 兩張表查詢出來的欄位名 必須是一致的, 沒有的欄位, 可以用 “ 0 as column ” 來補充。
1