惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
爱范儿
爱范儿
IT之家
IT之家
S
Secure Thoughts
WordPress大学
WordPress大学
P
Palo Alto Networks Blog
小众软件
小众软件
V
Visual Studio Blog
V
V2EX
人人都是产品经理
人人都是产品经理
AWS News Blog
AWS News Blog
美团技术团队
Jina AI
Jina AI
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
大猫的无限游戏
大猫的无限游戏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
SegmentFault 最新的问题
T
Tailwind CSS Blog
腾讯CDC
The Cloudflare Blog
The Hacker News
The Hacker News
Webroot Blog
Webroot Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
CXSECURITY Database RSS Feed - CXSecurity.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
L
Lohrmann on Cybersecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
博客园 - 司徒正美
月光博客
月光博客
J
Java Code Geeks
V2EX - 技术
V2EX - 技术
有赞技术团队
有赞技术团队
AI
AI
G
GRAHAM CLULEY
C
Cybersecurity and Infrastructure Security Agency CISA
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 叶小钗
S
Securelist
T
Threat Research - Cisco Blogs
C
Cisco Blogs

博客园 - antony.net

移动版网页自动缩放问题 2011年国内五款值得关注网店系统 Enterprise Architect 7 入门教程大全 Enterprise Architect 业务过程建模 不同浏览器处理后退的一些异同 - antony.net - 博客园 23个.NET开源项目 mysql 存储过程 游标 js代码库 table css 固定表头 - antony.net Hash Tables in Javascript 在非UI线程中改变UI控件属性的通用方法 RSClientPrint打印 文档格式批量转换(doc,txt,pdf等) 了解HTTP Headers的方方面面 XmlSerializer 常见问题疑难解答 webservices 水晶报表 - antony.net - 博客园 Build a Custom RadioButton Cell and Column for the DataGridView Control .NET 2.0 - WinForm Control - DataGridView 编程36计(二)
统计sql语句
antony.net · 2010-08-03 · via 博客园 - antony.net

--测试数据

DECLARE @t TABLE(ID int PRIMARY KEY,col decimal(10,2))

INSERT @t SELECT 1 ,26.21

UNION ALL SELECT 2 ,88.19

UNION ALL SELECT 3 , 4.21

UNION ALL SELECT 4 ,76.58

UNION ALL SELECT 5 ,58.06

UNION ALL SELECT 6 ,53.01

UNION ALL SELECT 7 ,18.55

UNION ALL SELECT 8 ,84.90

UNION ALL SELECT 9 ,95.60

--统计

SELECT a.Description,

Record_count=COUNT(b.ID),

[Percent]=CASE 

WHEN Counts=0 THEN '0.00%'

ELSE CAST(CAST(

COUNT(b.ID)*100./c.Counts

as decimal(10,2)) as varchar)+'%'

END

FROM(

SELECT sid=1,a=NULL,b=30  ,Description='<30' UNION ALL

SELECT sid=2,a=30  ,b=60  ,Description='>=30 and <60' UNION ALL

SELECT sid=3,a=60  ,b=75  ,Description='>=60 and <75' UNION ALL

SELECT sid=4,a=75  ,b=95  ,Description='>=75 and <95' UNION ALL

SELECT sid=5,a=95  ,b=NULL,Description='>=95' 

)a LEFT JOIN @t b 

ON (b.col<a.b OR a.b IS NULL)

AND(b.col>=a.a OR a.a IS NULL)

CROSS JOIN(

SELECT COUNTS=COUNT(*) FROM @t

)c

GROUP BY a.Description,a.sid,c.COUNTS

ORDER BY a.sid

/*--结果:

Description    Record_count  Percent

------------------- ------------------ ---------------------- 

<30          3            33.33%

>=30 and <60  2            22.22%

>=60 and <75  0            0.00%

>=75 and <95  3            33.33%

>=95         1            11.11%

--*/