一、背景
,,,, resc表保存了系统的一级,二级功能模块,同时保存了二级功能模块各页面的功能,通过pid定义了父子关系。
,,,,想通过resc表,整理出一份,一级,二级功能模块的对应关系,类似于这样的结果。
,,,,
二,实现方法
select case when PID=1, then & # 39;用户管理& # 39; when PID=4, then & # 39;代理管理& # 39; when PID=8, then & # 39;媒体管理& # 39; when PID=21, then & # 39;报表管理& # 39; when PID=26, then & # 39;内容管理& # 39; when PID=30, then & # 39;业绩管理& # 39; when PID=34, then & # 39;财务管理& # 39; 最终获得as 菜单, “名字”,PID 得到resc where pid 拷贝(select id 得到resc where pid=0) order by pid
执行结果:
将执行结果,粘贴到excel中,进行合并单元格,即可得到预期结果,可在excel中,对功能模块进行跟踪。
三、理论
案例表达式在sql中,可以实现if - then - else的逻辑。
有两种类型的情况下表达式:
- <李>
简单例表达式,使用表达式确定返回值;
李> <李>搜索案例表达式,使用条件确定返回值。
李>
- <李>
使用简单例表达式
李>- <李>
语法:
李>案例search_expression
,,,,当expression1 result1
编写此表达式
,,,,当expression2 result2
,,,…
,,,,当expressionN resultN
,,,,其他default_result
结束
- <李>
关键字说明:
李>- <李>
,,,, search_expression,待求值的表达式,数据表的某个字段;
李> <李>,,,, expressionX,是与search_expression进行比较的表达式;
李> <李>,,,, result1,编写此表达式是符合表达式时,返回的值
李> <李>,,,, default_result,是无法匹配表达式时,默认返回值。
李>
,,, 2。搜索案例表达式
- <李>
语法:
李>case
,,,,当condition1 result1
编写此表达式
,,,,当condition2 result2
,,,,…
,,,,当conditionN resultN
,,,,其他default_result
结束
- <李>
关键字说明:
李>- <李>
条件,是待求值的表达式;
李> <李>结果,是返回值,condition1为真,则返回result1,编写此表达式以此类推。
李> <李> default_result,是无法匹配表达式时,默认返回值。