declare @t table(name varchar(),type int)
insert into @t
select 'a',
union all select 'b',
union all select 'fb',
union all select 'fbf',
union all select 'fdfs', if object_id('test1') is not null
drop table test1
create table test1(
name varchar(),
type int)
insert into test1
select 'a',
union all select 'b',
union all select 'fb',
union all select 'fbf',
union all select 'fdfs', select * from test1 create function ss()
returns varchar()
as
begin
declare @sql varchar()
set @sql=''
select @sql=@sql+','+ name from test1
set @sql=stuff(@sql,,,' ')
return @sql
end select dbo.ss(),count_0=(select count() from test1 where type=),
count_1=(select count() from test1 where type=),
count_2=(select count() from test1 where type=)
/*
我想要的结果是这样的
name count_0 count_1 count_2
a,b,fb,fbf,fdfs 2 2 1 */

[SQL]SQL类似统计功能的sql文的更多相关文章

  1. C# SQL文件执行器的功能实现

    好一段时间没写博客了,这次我们来一起谈谈SQL文件执行器的功能实现,在ERP软件升级时往往在客户端程序更新的同时也要对数据库进行升级,ERP程序开发人员会对数据库升级的执行代码在开发的过程中以SQL文 ...

  2. c#Winform程序调用app.config文件配置数据库连接字符串 SQL Server文章目录 浅谈SQL Server中统计对于查询的影响 有关索引的DMV SQL Server中的执行引擎入门 【译】表变量和临时表的比较 对于表列数据类型选择的一点思考 SQL Server复制入门(一)----复制简介 操作系统中的进程与线程

    c#Winform程序调用app.config文件配置数据库连接字符串 你新建winform项目的时候,会有一个app.config的配置文件,写在里面的<connectionStrings n ...

  3. SQL点滴7—使用SQL Server的attach功能出现错误及解决方法

    原文:SQL点滴7-使用SQL Server的attach功能出现错误及解决方法 今天用SQL Server 2008的attach功能附加一个数据库,出了点问题,提示的错误是: Unable to ...

  4. sql 按年月日统计

    1.每年select year(ordertime) 年,sum(Total) 销售合计from 订单表group by year(ordertime) 2.每月select year(orderti ...

  5. SQL Server 类似正则表达式的字符处理问题

    SQL Serve提供了简单的字符模糊匹配功能,比如:like, patindex,不过对于某些字符处理场景还显得并不足够,日常碰到的几个问题有: 1. 同一个字符/字符串,出现了多少次 2. 同一个 ...

  6. SQL Server 2014新功能PPT

        本篇文章是我在公司内部分享SQL Server 2014新功能的PPT,在本PPT中我详细描述了SQL Server除了BI方面的新功能,以及提供了大量的测试.希望对大家有帮助.     请点 ...

  7. SQL Server 后续去除功能汇总

    原文:SQL Server 后续去除功能汇总 功能更新去除汇总 字段类型 在 Microsoft SQL Server 的未来版本中将删除 ntext.text 和 image 数据类型. 请避免在新 ...

  8. (原)SQL Server 系统提供功能的三个疑惑

    本文目录列表: 1.SQL Server系统提供的部分疑惑概述2.系统函数调用时DEFAULT代替可选参数使用不统一3.队列字段列message_enqueue_time记录的是UTC日期时间 4.@ ...

  9. Python和SQL 2017的强大功能

    Python和SQL Server 2017的强大功能   原文来自:https://www.red-gate.com/simple-talk/sql/sql-development/power-py ...

随机推荐

  1. Linux-remote change password (more)

    1.creat managment Certification on Mangar Serverssh-keygen -t rsa2.creat client Certification on Cli ...

  2. Mysql函数FIND_IN_SET()的使用方法

    有了FIND_IN_SET这个函数.我们可以设计一个如:一只手机即是智能机,又是Andriod系统的. 比如:有个产品表里有一个type字段,他存储的是产品(手机)类型,有 1.智能机,2.Andri ...

  3. SwiftyJSON 中文介绍

    SwiftyJSON makes it easy to deal with JSON data in Swift. Why is the typical JSON handling in Swift ...

  4. sklearn小知识

    特征缩放:# 为了追求机器学习和最优化算法的最佳性能,我们将特征缩放 from sklearn.preprocessing import StandardScaler sc = StandardSca ...

  5. log4j日志的打印

    1.加入日志属性文件 log4j.properties log4j.rootLogger=DEBUG,Console,fileout log4j.appender.Console=org.apache ...

  6. ChinaUnix上的帮助手册还不错!

    无意中发现ChinaUnix上的Linux帮助手册还真不错啊,有时间多看一看: http://man.chinaunix.net/linux/debian/debian_learning/index. ...

  7. POJ #1042 Gone Fishing - WA by a DP solution. TODO

    I used DP instead of Greedy. But got WA on PoJ, though it passed all web-searched cases. Maybe I hav ...

  8. RPM Fusion on CentOS7

    RPM Fusion RPM Fusion provides software that the Fedora Project or Red Hat doesn't want to ship. Tha ...

  9. 【Android学习日记】

    (一) Android 开发基础 1 Android平台的特性 1)  应用程序框架支持组建的重用和替换,包括打电话应用程序.文件管理器等. 2)  Dalvik虚拟机专门为移动设备做了优化,Dalv ...

  10. s3c2440存储控制器和地址以及启动的理解

    转自:http://blog.sina.com.cn/s/blog_5ddb672b0100fkcf.html 1.首先应该先了解Flash ROM的种类 NOR FLASH地址线和数据线分开,来了地 ...