select platform, user_name, min(user_ip) ip, min(login_time) time from ( select * from login_201510 union all select * from login_201511 union all select * from login_201512 union all select * from login_201601 union all select * from login_201602 union all select * from login_201603 union all select * from login_201604 union all select * from login_201605 union all select * from login_201606 ) t where user_name is not null group by platform, user_name having min(login_time) >= unix_timestamp('2011-01-01') + -3600 and min(login_time) < unix_timestamp('2016-07-01') + -3600 limit 100;
復(fù)制代碼
其中 UNION ALL 這塊
select * from login_201510 union all select * from login_201511 union all select * from login_201512 union all select * from login_201601 union all select * from login_201602 union all select * from login_201603 union all select * from login_201604 union all select * from login_201605 union all select * from login_201606
復(fù)制代碼
執(zhí)行約26秒,有960W左右記錄數(shù),但是整體執(zhí)行會(huì)error~~ ENGINE=BRIGHTHOUSE ,有人能點(diǎn)撥一下嗎?謝謝!作者: 王楠w_n 時(shí)間: 2016-09-06 15:53
你用程序 取出每個(gè)表的數(shù)據(jù) 然后自己在遍歷下作者: stay_sun 時(shí)間: 2016-09-06 15:55
取出 每個(gè)月的 需要的值 用程序遍歷下 取出結(jié)果 作者: seesea2517 時(shí)間: 2016-09-06 17:18
會(huì)error,error是啥樣的呢?作者: seesea2517 時(shí)間: 2016-09-06 17:36
可以嘗試把 where 條件放到每一個(gè) union 的子查詢里用,甚至把 group by 也放進(jìn)去處理,最后再 union 一起后(或使用臨時(shí)表,把每一個(gè)子查詢結(jié)果插入到臨時(shí)表),再做一次整體的 group by 處理過(guò)濾出想要的數(shù)據(jù)。 作者: ganluo960214 時(shí)間: 2016-09-07 11:51
我覺(jué)得 是不是滿在合并數(shù)據(jù)的地方 你這表的字段很多?作者: MrQing 時(shí)間: 2016-09-07 15:23 回復(fù) 6# ganluo960214