[SQL]SQL类似统计功能的sql文
2014-03-24 20:24
113 查看
declare @t table(name varchar(20),type int) insert into @t select 'a',0 union all select 'b',0 union all select 'fb',1 union all select 'fbf',2 union all select 'fdfs',1 if object_id('test1') is not null drop table test1 create table test1( name varchar(20), type int) insert into test1 select 'a',0 union all select 'b',0 union all select 'fb',1 union all select 'fbf',2 union all select 'fdfs',1 select * from test1 create function ss() returns varchar(1000) as begin declare @sql varchar(1000) set @sql='' select @sql=@sql+','+ name from test1 set @sql=stuff(@sql,1,1,' ') return @sql end select dbo.ss(),count_0=(select count(1) from test1 where type=0), count_1=(select count(1) from test1 where type=1), count_2=(select count(1) from test1 where type=2) /* 我想要的结果是这样的 name count_0 count_1 count_2 a,b,fb,fbf,fdfs 2 2 1 */
相关文章推荐
- [SQJ]sql如何实现类似统计的功能
- druid发布0.2.1版,增加sql统计的merge功能。
- 类似SQL 的Group by功能
- 利用SQL*PLUS导出成EXCEL和html的功能实现报表统计:
- 一个SQL语句实现的统计功能
- SQL统计功能的Java实现
- PL/SQL中使用EXISTS:使用LOOP循环替代或者SELECT实现类似的功能:
- 第十三周 项目5:(1)阅读程序,完成类似的字符串统计功能
- Sql 类似?: 功能的函数
- 实现split类似功能的sql语句
- Oracle自动导入数据文件(类似bcp的功能)及问题记录SQL*LOADER-704,ORA-12504
- 实现类似LINQ TO SQL的功能, 轻量级的数据访问组件
- mongod统计(类似sql group by)aggregate函数使用方法
- springmvc使用SQL的统计功能
- SQL统计功能的Java实现
- 完整的利用xp_cmdshell在T-SQL中执行类似创建目录的功能
- sql笔记-group by 统计功能
- SQL实现类似C#的Split()函数的功能
- SQL里实现类似SPLIT功能
- MySQL ,MS SQL Server,类似功能的函数