表1:
select s.SHOP_ID, t.seller_nick, date_format(t.created,'%H') as time, sum(payment) as gmv, sum(received_payment) as payment from v_shop s left join tcc_trades t on s.shop_name = t.seller_nick where s.SEL_ITEM_ID = 1 and t.created between '2016-11-17' and '2016-11-18' and t.pay_time > '2010-01-01' group by s.SHOP_ID, time order by seller_nick
数据:
shop_id seller_nick gmv payment
16 6ixty8ight官方旗舰店 04 342.00 0.00
16 6ixty8ight官方旗舰店 06 103.50 0.00
16 6ixty8ight官方旗舰店 08 299.50 0.00
26 AEON官方海外旗舰店 17 0.00 0.00
26 AEON官方海外旗舰店 16 0.00 0.00
表2:
select s.SHOP_ID, seller_nick, date_format(r.created,'%H') as time, sum(refund_fee) as refund from v_shop s left join tcc_refunds r on s.SHOP_NAME = r.seller_nick where s.SEL_ITEM_ID = 1 and r.created between '2016-11-17' and '2016-11-18' group by r.seller_nick, time order by seller_nick
数据:
shop_id seller_nick time refund
16 6ixty8ight官方旗舰店 00 1960.10
16 6ixty8ight官方旗舰店 01 583.95
16 6ixty8ight官方旗舰店 06 89.36
26 aeon官方海外旗舰店 10 77644.00
求得2张表合并后的整点数据,注意表1有的时间表2不一定有,求得从0-23个整点的数据
希望的结果是这样的:
shop_id seller_nick time gmv payment refund
16 6ixty8ight官方旗舰店 00 0.00 0.00 1960.10
16 6ixty8ight官方旗舰店 01 0.00 0.00 583.95
16 6ixty8ight官方旗舰店 04 342.00 0.00 0.00
16 6ixty8ight官方旗舰店 06 103.50 0.00 89.36
16 6ixty8ight官方旗舰店 08 299.50 0.00 0.00
求大神赐教。
这个实现起来,不难啊
根据seller_nick 和 timez 字段,来合并就行啦,
思路:
step1,创建两个临时表,存储中间结果集,你的两条查询语句返回的结果集
step2,根据seller_nick 和 timez 字段,合并后,去重,然后再跟临时表连接,就能得出结果集啦