建表:

CREATE TABLE `my_tb` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_code` varchar(255) DEFAULT NULL,
`code` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

初始数据:

INSERT INTO `my_tb` (  `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');
INSERT INTO `my_tb` ( `parent_code`, `code`) VALUES ('', '');

查询行号:

-- 生成 行号
select @r:=@r+1 as row_num , a.* from my_tb a ,(select @r:=0) b

显示分组号:

-- 生成 分组排序号

select
@group_row:=CASE when @parent_code=a.parent_code then @group_row+1 else 1 end as groupRow,
@parent_code:=a.parent_code as parent_code,
a.code from my_tb a ,( select @group_row:=1, @parent_code:='') as b
ORDER BY a.parent_code , a.code

最新文章

  1. CentOS随笔 不断添加
  2. 阿里巴巴Java招聘
  3. Changing the Color of Linux ls Command 改变Linux的ls命令显示的颜色
  4. AndroidPn源码分析(一)
  5. 解决Mac下GDB提示签名错误
  6. 【HDU 2222】Keywords Search AC自动机模板题
  7. OneDrive无法正常登录
  8. EF数据库连接时候出错
  9. 测序深度和覆盖度(Sequencing depth and coverage)
  10. Qt Charts
  11. 【转】Android之内存泄漏调试学习与总结
  12. mysqlbackup 备份失败的分析
  13. c/c++ 栈与队列实现车库的出入与收费
  14. Python基础之模块与包
  15. Arch Linux安装后的一些初始设置简介
  16. 前端 搜索样式 html
  17. 【LeetCode每天一题】Longest Valid Parentheses(最长有效括弧)
  18. Beta阶段冲刺---Day2
  19. 阿里巴巴java手册示例
  20. abcdocker 的博客

热门文章

  1. VS2013编译经常卡在正在从以下位置加载xxx.dll的符号
  2. 在Windows Server 2012的Task Scheduler里面配置自动发送邮件
  3. 如何处理Win7连接vpn时报错789的问题
  4. Zabbix监控Windows事件日志
  5. Python LDAP中的时间戳转换为Linux下时间
  6. 虚方法的调用是怎么实现的(单继承VS多继承)
  7. 轻松搞定面试中的二叉树题目(java&python)
  8. [转]java byte 数据类型(基础)
  9. CSV - 操作比较
  10. 【分享】分享一个压缩 PNG 的网站 TinyPNG