首页 > 代码库 > mysql 类似rownum改写功能
mysql 类似rownum改写功能
create table `sq` ( `id` int , `user_id` varchar (45), `userid_seq` varchar (45) ); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘1‘,‘zhang‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘2‘,‘wang‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘3‘,‘han‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘4‘,‘zhang‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘5‘,‘zhang‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘6‘,‘wang‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘7‘,‘han‘,NULL); insert into `sq` (`id`, `user_id`, `userid_seq`) values(‘8‘,‘zhang‘,NULL);
实现相同user_id产生一个类似rownum序号功能
实现语句
select a.*,(select count(*) from sq b where b.user_id=a.user_id and b.id <= a.id ) as seqno from sq a;
某个id最大的序列号 也就是有多少条
select max(seqno) from (select a.*,(select count(*) from sq b where b.user_id=a.user_id and b.id <= a.id ) as seqno from sq a where user_id=‘zhang‘) as c;
本文出自 “深山有dba” 博客,请务必保留此出处http://19801021.blog.51cto.com/7262596/1585984
mysql 类似rownum改写功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。