参考http://www.cnblogs.com/CharlieLau/p/6737243.html
DROP TABLE IF EXISTS `ads_credit_applylog`;
CREATE TABLE `ads_credit_applylog` (`id` varchar(20) NOT NULL,
`customer_id` varchar(20) DEFAULT NULL,
`ips` int(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of ads_credit_applylog
-- ----------------------------
INSERT INTO `ads_credit_applylog` VALUES ('1', '15588', '921');
INSERT INTO `ads_credit_applylog` VALUES ('2', '15588', '597');
INSERT INTO `ads_credit_applylog` VALUES ('3', '15588', '483');
INSERT INTO `ads_credit_applylog` VALUES ('4', '15588', '1000');
INSERT INTO `ads_credit_applylog` VALUES ('5', '12619', '421');
INSERT INTO `ads_credit_applylog` VALUES ('6', '12619', '358');
INSERT INTO `ads_credit_applylog` VALUES ('7', '12619', '523');
INSERT INTO `ads_credit_applylog` VALUES ('8', '12619', '879');
select (@i := case when @pre_parent_code=customer_id then @i + 1 else 1 end ) rownum,
customer_id,ips,(@pre_parent_code:=customer_id)
from (select customer_id,ips from ads_credit_applylog order by customer_id,ips desc ) a ,
(SELECT @i := 0, @pre_parent_code:='') AS b
group by customer_id ,ips desc
order by customer_id,ips desc,rownum