mysql 显示行号,以及分组排序
2024-09-16 05:53:06
建表:
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
最新文章
- CentOS随笔 不断添加
- 阿里巴巴Java招聘
- Changing the Color of Linux ls Command 改变Linux的ls命令显示的颜色
- AndroidPn源码分析(一)
- 解决Mac下GDB提示签名错误
- 【HDU 2222】Keywords Search AC自动机模板题
- OneDrive无法正常登录
- EF数据库连接时候出错
- 测序深度和覆盖度(Sequencing depth and coverage)
- Qt Charts
- 【转】Android之内存泄漏调试学习与总结
- mysqlbackup 备份失败的分析
- c/c++ 栈与队列实现车库的出入与收费
- Python基础之模块与包
- Arch Linux安装后的一些初始设置简介
- 前端 搜索样式 html
- 【LeetCode每天一题】Longest Valid Parentheses(最长有效括弧)
- Beta阶段冲刺---Day2
- 阿里巴巴java手册示例
- abcdocker 的博客
热门文章
- VS2013编译经常卡在正在从以下位置加载xxx.dll的符号
- 在Windows Server 2012的Task Scheduler里面配置自动发送邮件
- 如何处理Win7连接vpn时报错789的问题
- Zabbix监控Windows事件日志
- Python LDAP中的时间戳转换为Linux下时间
- 虚方法的调用是怎么实现的(单继承VS多继承)
- 轻松搞定面试中的二叉树题目(java&;python)
- [转]java byte 数据类型(基础)
- CSV - 操作比较
- 【分享】分享一个压缩 PNG 的网站 TinyPNG