一條語(yǔ)句沒法實(shí)現(xiàn)的...

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的紅崗網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
create table table2 select * from table1 order by id limit 1,100
create table table3 select * from table1 order by id limit 100,100
create table table4 select * from table1 order by id limit 200,100
呵呵,這個(gè)還不好辦么,你寫的語(yǔ)句類似這個(gè)吧 我用C++語(yǔ)法給你寫吧,希望能給你點(diǎn)提示
int a;
a=x_id%9
CString tbl_name
tbl_name="A_"+a;
CString Sql;
Sql="select * from" + tblname;
1、做分區(qū)表,(哪個(gè)字段分區(qū)很重要,分錯(cuò)會(huì)影響性能)。
2、拆表,
可以將歷史數(shù)據(jù)放到 其他表中,例如 abc表中,2013年的數(shù)據(jù),拆到 abc_2013表中,2014年的數(shù)據(jù)拆到abc_2014表中。
SELECT MAX(login_time) AS login_time,user_id
FROM(
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20170101 GROUP BY user_id
UNION
SELECT MAX(login_time) AS login_time,user_id FROM user_login_record_20180101 GROUP BY user_id
)TMP GROUP BY user_id
覺得你還是應(yīng)該用php去寫。非要用mysql本身的話給個(gè)參考:
mysql?select?*?from?a;
+------+--------+------+----+
|?id???|?name???|?num1?|?bb?|
+------+--------+------+----+
|????1?|?a,?????|????2?|??3?|
|????2?|?b,c,???|????2?|??4?|
|????3?|?d,e,f,?|????2?|??5?|
+------+--------+------+----+
3?rows?in?set?(0.00?sec)
mysql?delimiter?//
mysql?create?procedure?`strsplit1`(in?str3?varchar(2))
-?begin
-??declare?i?int(10);
-??declare?j?int(10);
-??declare?k?int(10);
-??declare?str1?varchar(100);
-?????????declare?str4?varchar(1000);
-??declare?str5?varchar(100);
-
-??select?count(*)?into?i?from?a;
-??if?i!=0?then
-??????????drop?table?if?exists?tmp_table1;
-??????????CREATE?TEMPORARY?TABLE?tmp_table1?like?a;
-??end?if;
-
-??set?j=0;
-??while?ji?do
-??????????select?id,name?into?str1,str4?from?a?limit?j,1;
-??????????select?instr(str4,str3)?into?k?from?dual;
-??????????if?k=0?then
-??????????????????insert?into?tmp_table1(id,name)?values(str1,str4);
-??????????end?if;
-??????????while?k!=0?do
-??????????????????select?substring_index(str4,str3,1)?into?str5?from?dual;
-??????????????????insert?into?tmp_table1(id,name)?values(str1,str5);
-??????????????????select?mid(str4,k+1)?into?str4?from?dual;
-??????????????????select?instr(str4,str3)?into?k?from?dual;
-??????????end?while;
-??set?j=j+1;
-??end?while;
-
-?select?*?from?tmp_table1;
-?end
-?//
Query?OK,?0?rows?affected?(0.00?sec)
mysql??delimiter?;
最后結(jié)果:
mysql?call?strsplit1(',');
+------+------+------+----+
|?id???|?name?|?num1?|?bb?|
+------+------+------+----+
|????1?|?a????|?NULL?|??1?|
|????2?|?b????|?NULL?|??2?|
|????2?|?c????|?NULL?|??3?|
|????3?|?d????|?NULL?|??4?|
|????3?|?e????|?NULL?|??5?|
|????3?|?f????|?NULL?|??6?|
+------+------+------+----+
6?rows?in?set?(0.25?sec)
Query?OK,?0?rows?affected?(0.30?sec)
三百萬(wàn)左右的數(shù)據(jù),說(shuō)大不大,說(shuō)小也不小了。
這個(gè)數(shù)據(jù)量,做好索引的話,暫時(shí)還不需要拆表存儲(chǔ)。
不過(guò)考慮以后還會(huì)有大量數(shù)據(jù)存入的話,你可以做一下拆表計(jì)劃了。
當(dāng)前題目:mysql怎么拆表,mysql改表
分享地址:http://chinadenli.net/article27/dsgisjj.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站維護(hù)、靜態(tài)網(wǎng)站、域名注冊(cè)、網(wǎng)站改版、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)