with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Shanghai' city from dual union all select 'China' nation ,'Beijing' city from dual union all select 'USA' nation ,'New York' city from dual union all se…
11g里面用listagg: select listagg(name,',') within (order by id) from table 10g里面用wm_concat:select wm_concat(name) from table wm_concat是undocument的listagg是11g document的…
未合并情况 SELECT a.id, b.name AS "role" FROM sys_user a INNER JOIN sys_user_role c ON a.id=c.user_id INNER JOIN sys_role b ON b.id =c.role_idWHERE a.del_flag=0 AND b.del_flag=0 结果 id role 1 系统管理员1 测试角色2 系统管理员2  测试角色9 系统管理员9 测试角色d11828f3dbf148829287a…
stuff(select ',' + fieldname from tablename for xml path('')),1,1,'') 这一整句的作用是将多行fieldname字段的内容串联起来,用逗号分隔.例如表fieldname-----------AAABBBCCC串联之后就是字符串: AAA,BBB,CCCfor xml path是SQL Server 2005以后版本支持的一种生成XML的方式.具体如何使用,请参考联机丛书.stuff函数的作用是去掉字符串最前面的逗号分隔符. --…
例子: select wm_concat(roleid) from lbmember where userid = ? 值的形式:1,2,3 下面是把1,2,3转换为1;2;3select replace((select wm_concat(roleid) from lbmember where userid = ?),',',';') from dual…
USE [FM_Dev] GO /****** 对象: UserDefinedFunction [dbo].[GetClassNameByStudentCode] 脚本日期: 05/23/2014 17:20:43 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: 2014年5月7日…
原SQL AND acc.id = accRole.acc_id) AND accRole.role_id = T_PM_ROLE.id ORDER BY acc.id 结果,有一个人有两个角色,如果想要将两个角色合并该如何呢? 答案:使用 group_concat函数 注:group_concat只有与group by语句同时使用才能产生效果 AND acc.id = accRole.acc_id) AND accRole.role_id = T_PM_ROLE.id GROUP BY acc…
注:本文来源:远方的守望者  <oracle提高查询效率的34条方法> oracle提高查询效率的34条方法 1.选择最有效率的表名顺序 (只在基于规则的优化器中有效): ORACLE的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最先处理,在FROM子句中包含多个表的情况下,你必须选择记录条数最少的表作为基础表.如果有3个以上的表连接查询, 那就需要选择交叉表(intersection table)作为基础表, 交叉表是…
sql语句中,查询分组中前n条记录的sql语句如下 第一种方法 select * from consultingfeebill awhere n>(select count(*) from consultingfeebill where a.FundAccountType=FundAccountTypeand TradeAmount>a.TradeAmount)order by TradeAmount desc 第二种方法 select * from consultingfeebill a w…
MySQL RAND()函数调用可以在0和1之间产生一个随机数: mysql> SELECT RAND( ), RAND( ), RAND( ); +------------------+-----------------+------------------+ | RAND( ) | RAND( ) | RAND( ) | +------------------+-----------------+------------------+ | 0.45464584925645 | 0.18244…