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

推荐订阅源

L
LangChain Blog
C
Check Point Blog
博客园 - Franky
V
Visual Studio Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
V2EX - 技术
V2EX - 技术
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
Jina AI
Jina AI
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
H
Hacker News: Front Page
H
Hackread – Cybersecurity News, Data Breaches, AI and More
O
OpenAI News
Attack and Defense Labs
Attack and Defense Labs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
爱范儿
爱范儿
H
Heimdal Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
Google Developers Blog
G
GRAHAM CLULEY
V
V2EX
The Register - Security
The Register - Security
人人都是产品经理
人人都是产品经理
B
Blog RSS Feed
Schneier on Security
Schneier on Security
M
MIT News - Artificial intelligence
Stack Overflow Blog
Stack Overflow Blog
Help Net Security
Help Net Security
大猫的无限游戏
大猫的无限游戏
C
CERT Recently Published Vulnerability Notes
The GitHub Blog
The GitHub Blog
V
Vulnerabilities – Threatpost
The Last Watchdog
The Last Watchdog
J
Java Code Geeks
S
Secure Thoughts
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
量子位
NISL@THU
NISL@THU
K
Kaspersky official blog
Engineering at Meta
Engineering at Meta
T
Threatpost
Recent Commits to openclaw:main
Recent Commits to openclaw:main
宝玉的分享
宝玉的分享
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
博客园_首页
A
Arctic Wolf

博客园 - 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%

--*/