求一条SQL语句
时间:2011-12-12
来源:互联网
--原数据 col1 col2 col3 col4 col5 col6 ....... AAA BBB CCC 1 0 1 col1 col2 col3 col4 col5 col6 ....... AAA BBB CCC 3 7 9 col1 col2 col3 col4 col5 col6 ....... AAA EEE CCC 5 3 2 col1 col2 col3 col4 col5 col6 ....... AAA BBB DDD 5 3 2
SQL code
--想要的结果 col1 col2 col3 col4 col5 col6 ....... AAA BBB CCC 1 0 1 3 7 9 AAA EEE CCC 5 3 2 AAA BBB DDD 5 3 2 要的结果就是前面三个字段值相同的只显示一行,后面字段的值也不合并就在原行里显示!
作者: custom1234 发布时间: 2011-12-12
select col1=(case when no=1 then col1 else '' end), col2=(case when no=1 then col1 else '' end), col3=(case when no=1 then col1 else '' end),col4..... from (select no=row_number() over(partition by col1,col2,col3 order by getdate()),* from tb) t
作者: ssp2009 发布时间: 2011-12-12
select case px when 1 then col1 else '' end as col1, case px when 1 then col2 else '' end as col2, case px when 1 then col3 else '' end as col3, * from (select px=row_number()over(partition by col1,col2,col3 order by getdate()),* from tb)t
作者: fredrickhu 发布时间: 2011-12-12
--想要的结果 ID col1 col2 col3 col4 col5 col6 ....... 1 AAA BBB CCC 1 0 1 3 7 9 2 AAA EEE CCC 5 3 2 3 AAA BBB DDD 5 3 2 在记录前加一个序列号呢?
作者: custom1234 发布时间: 2011-12-12
select px,col1=(case when no=1 then col1 else '' end), col2=(case when no=1 then col1 else '' end), col3=(case when no=1 then col1 else '' end),col4..... from (select no=row_number() over(partition by col1,col2,col3 order by getdate(), px=rank() over(order by col1,col2,col3),* from tb) t
作者: ssp2009 发布时间: 2011-12-12
select case px when 1 then rankid else '' end as id, case px when 1 then col1 else '' end as col1, case px when 1 then col2 else '' end as col2, case px when 1 then col3 else '' end as col3, * from (select rankid=DENSE_RANK()over(partition by col1,col2,col3 order by getdate()), px=row_number()over(partition by col1,col2,col3 order by getdate()), * from tb)t
作者: fredrickhu 发布时间: 2011-12-12
SQL code
select px,col1=(case when no=1 then col1 else '' end),
col2=(case when no=1 then col1 else '' end),
col3=(case when no=1 then col1 else '' end),col4.....
from (select no=row_n……
SQL code
--不好意思,两位!刚才说错了,是一个完整的序号流水号:因为我想用这个ID来排序! ID col1 col2 col3 col4 col5 col6 ....... 1 AAA BBB CCC 1 0 1 2 3 7 9 3 AAA EEE CCC 5 3 2 4 AAA BBB DDD 5 3 2
作者: custom1234 发布时间: 2011-12-12
select id=row_number()over(order by getdate()), case px when 1 then rankid else '' end as id, case px when 1 then col1 else '' end as col1, case px when 1 then col2 else '' end as col2, case px when 1 then col3 else '' end as col3, * from (select px=row_number()over(partition by col1,col2,col3 order by getdate()),* from tb)t
作者: fredrickhu 发布时间: 2011-12-12
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28