亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 請(qǐng)教一個(gè)sql語(yǔ)句優(yōu)化的問(wèn)題 [打印本頁(yè)]

作者: MrQing    時(shí)間: 2016-09-06 13:39
標(biāo)題: 請(qǐng)教一個(gè)sql語(yǔ)句優(yōu)化的問(wèn)題
本人小白,請(qǐng)教個(gè)sql語(yǔ)句優(yōu)化的問(wèn)題

SQL:
  1. 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 這塊
  1. 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

字段不算太多。 最后是分開處理的,就寫成子句來(lái)執(zhí)行。。~
作者: MrQing    時(shí)間: 2016-09-07 15:23
回復(fù) 5# seesea2517

謝謝,我嘗試一下




歡迎光臨 Chinaunix (http://72891.cn/) Powered by Discuz! X3.2