´óÊý¾ÝϵÄsqlÓï¾äʹÓÃ

2015-07-21 16:26:04 ¡¤ ×÷Õß: ¡¤ ä¯ÀÀ: 0

£¨Ò»£© 
 mysql limit´óÊý¾ÝÁ¿·ÖÒ³ÓÅ»¯·½·¨
 

Ê×ÏÈ´´½¨Ò»¸ö±í

CREATE TABLE `ipdatas` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(8) NOT NULL DEFAULT '0',
  `ipaddress` varchar(50) NOT NULL,
  `source` varchar(255) DEFAULT NULL,
  `track` varchar(255) DEFAULT NULL,
  `entrance` varchar(255) DEFAULT NULL,
  `createdtime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `createddate` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`id`),
  KEY `uid` (`uid`)
) ENGINE=MyISAM AUTO_INCREMENT=68293856 DEFAULT CHARSET=utf8;


²åÈë´óÁ¿Êý¾Ý100Íò

begin

	declare i int; 
set i = 10001 ;  
	
	 myLoop: LOOP  
      
      
        if i = 100000 then   
        leave myLoop;  
        end if;  
          
        /* do something */  
        -- Ñ­»·Êä³öÐÅÏ¢
 

	
insert into `ipdatas`(`uid`,`ipaddress`,`source`,`track`,`entrance`,`createdtime`,`createddate`)
				values(i,'127.0.0.1','wanglitao','guoyanhui','127.0.0.1',now(),now());
      
set i = i +1;
    /* Ñ­»·½áÊø */  
    end loop myLoop; 

end


ÓÅ»¯Óï¾ä

Ô­Óï¾ä

select * from ipdatas order by id limit 900000,100

ÊÜÓ°ÏìµÄÐÐ: 0
ʱ¼ä: 16.408s

ÓÅ»¯Óï¾ä

Select * From ipdatas Where id>=(
Select id from ipdatas order by id limit 900000,1
)limit 100;