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

推荐订阅源

C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
WordPress大学
WordPress大学
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
aimingoo的专栏
aimingoo的专栏
C
Check Point Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Tor Project blog
P
Proofpoint News Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Latest news
Latest news
L
LINUX DO - 热门话题
罗磊的独立博客
T
Tenable Blog
The Hacker News
The Hacker News
美团技术团队
N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
博客园 - 司徒正美
Jina AI
Jina AI
Cyberwarzone
Cyberwarzone
云风的 BLOG
云风的 BLOG
S
Secure Thoughts
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
Spread Privacy
Spread Privacy
U
Unit 42
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
爱范儿
爱范儿
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
P
Palo Alto Networks Blog
Google Online Security Blog
Google Online Security Blog
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
Help Net Security
Help Net Security
Hacker News: Ask HN
Hacker News: Ask HN
F
Full Disclosure
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Security Affairs
Project Zero
Project Zero

博客园 - lrary

JavaScript经典技巧 - lrary - 博客园 动态添加ASP.NET控件并绑定处理事件一例 - lrary - 博客园 脚本收藏 - lrary - 博客园 一些sql语句的详细解释[转] 特殊的DataGrid的绑定 - lrary - 博客园 纯脚本搞掂DataGrid表表头不动,表身滚动。(转摘) - lrary - 博客园 检验密码强度的JS类 - lrary - 博客园 数据库设计规范 V2.0 DataGrid 多行 DataGrid怎么产生一个分类的题头 AJAX 在.net的应用 sql怎么使用外连接 Asp.NET程序中常用的三十三种代码 检测含有中文字符串的实际长度 根据区位得到汉字拼音首字母(c#) 认识ASP.NET配置文件Web.config Asp.net(C#)实现验证码功能 给Repeater、Datalist和Datagrid增加自动编号列 查找和统计页面上控件
SQL语句特---殊统计(1)
lrary · 2006-05-13 · via 博客园 - lrary

表Table1:  
  项目 金额  
  X1 100  
  X2 120  
  Y1   Y3 180  
  Y2 90  
  Z1 140  
  A1   A2   B1                   300  
  B2   Z2   C1                   150  
  要得到以下结果:  
  项目 金额  
  A 200  
  B 150  
  C 50  
  X 220  
  Y 270  
  Z 190  
  注:即头字母相同的累加,一个项目中如果有多于一个值则等分(如A1   A2   B1:300则A   200,B   100)。

解决方法:

create   table   Table1(项目   varchar(20),金额   int)   
  
insert   Table1   select   'X1'                         ,100   
  
union     all         select   'X2'                         ,120   
  
union     all         select   'Y1       Y3'               ,180   
  
union     all         select   'Y2'                         ,90   
  
union     all         select   'Z1'                         ,140   
  
union     all         select   'A1     A2       B1',300   
  
union     all         select   'B2       Z2   C1'         ,150   
  
go   
  
select * from table1
  
--查询处理   
    
  
--处理临时表   
  declare   @i   int   
  
select   @i=max(len(项目))   from   Table1   
  
set   rowcount   @i   
  
select   id=identity(int)   into   #t   from   syscolumns   a,syscolumns   b   
  
set   rowcount   0   
    
  
--统计出结果   
  select   项目,项目1=substring(a.项目,b.id,1),金额   
  
into   #t1   from   Table1   a,#t   b   
  
where   len(a.项目)>=b.id   and   patindex('   [^   ]%',substring('   '+a.项目,b.id,8000))=1   
    
  
select   项目=a.项目1,金额=sum(a.金额/b.cnt)     
  
from   #t1   a,(select   项目,cnt=count(*)   from   #t1   group   by   项目)b   
  
where   a.项目=b.项目   
  
group   by   a.项目1   
    
  
drop   table   #t,#t1   
  
go   
    
  
--删除测试   
  drop   table   Table1