博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
去掉重复的列名.txt
阅读量:4704 次
发布时间:2019-06-10

本文共 1043 字,大约阅读时间需要 3 分钟。

declare @t table(编号 varchar(6),名称 varchar(6),数量 int)
insert @t select '001',  'AAA',   10
union all select '001',  'AAA',   3
union all select '001',  'AAA',   50
union all select '001',  'AAA',   70
union all select '001',  'AAA',   18
union all select '002',  'BBB',   10
union all select '002',  'BBB',   20
union all select '002',  'BBB',   40
union all select '002',  'BBB',   60
union all select '002',  'BBB',   80
union all select '003',  'CCC',   10
union all select '003',  'CCC',   110
union all select '003',  'CCC',   150
union all select '003',  'CCC',   120
union all select '003',  'CCC',   130
---查看测试数据
select * from @t
---查看结果
select
  case when not exists (select 1 from @t where 编号=a.编号 and 名称=a.名称 and 数量<a.数量) then 编号 else '' end as 编号,
  case when not exists (select 1 from @t where 编号=a.编号 and 名称=a.名称 and 数量<a.数量) then 名称 else '' end as 名称,
  数量     
from @t a
group by 编号,名称,数量
/*
编号     名称     数量          
------ ------ -----------
001    AAA    3
              10
              18
              50
              70
002    BBB    10
              20
              40
              60
              80
003    CCC    10
              110
              120
              130
              150
(所影响的行数为 15 行)
*/

转载于:https://www.cnblogs.com/shihao/archive/2012/05/21/2511190.html

你可能感兴趣的文章
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
memcached 细究(三)
查看>>
RSA System.Security.Cryptography.CryptographicException
查看>>
webservice整合spring cxf
查看>>
[解题报告] 100 - The 3n + 1 problem
查看>>
Entity Framework 学习高级篇1—改善EF代码的方法(上)
查看>>
Mybatis逆向工程配置文件详细介绍(转)
查看>>
String类的深入学习与理解
查看>>
不把DB放进容器的理由
查看>>
OnePage收集
查看>>
Java parseInt()方法
查看>>
yahoo的30条优化规则
查看>>
[CCF2015.09]题解
查看>>