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

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Cisco Blogs
T
The Exploit Database - CXSecurity.com
G
GRAHAM CLULEY
AI
AI
腾讯CDC
月光博客
月光博客
P
Privacy International News Feed
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
Latest news
Latest news
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
H
Hacker News: Front Page
博客园 - 【当耐特】
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
D
Docker
D
DataBreaches.Net
O
OpenAI News
IT之家
IT之家
T
Threat Research - Cisco Blogs
S
Securelist
S
Secure Thoughts
V
Visual Studio Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
A
Arctic Wolf
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tor Project blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
Help Net Security
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - Franky
C
Check Point Blog
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
Forbes - Security
Forbes - Security
F
Full Disclosure
S
Security @ Cisco Blogs
B
Blog RSS Feed

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

--*/