***数据表如何换化显示问题***
时间:2011-12-05
来源:互联网
ID TYPE length
5309622 DT 30.00
8002619 BR 15.00
1002619 CO 30.00
1002619 BR 30.00
需要转化成,列名无所谓
5309622 CA100 -----(固定值)
DT 30.00
8002619 CA100
BR 15.00
1002619 CA100 -----有2条相同ID,应该显示如下
CO 30.00
BR 30.00
作者: bigmingming 发布时间: 2011-12-05
作者: ssp2009 发布时间: 2011-12-05
DT 30.00
8002619 CA100
BR 15.00
1002619 CA100 -----有2条相同ID,应该显示如下
CO 30.00
BR 30.00
作者: bigmingming 发布时间: 2011-12-05
换一行显示 TYPE,LENTH, ID相同时,只显示一次ID行
作者: bigmingming 发布时间: 2011-12-05
select case px when 1 then id else '' end as ID , case px when 1 then TYPE else '' end as TYPE,length from (select px=row_number()over(partition by id order by getdate()),* from tb)t
作者: fredrickhu 发布时间: 2011-12-05
SQL code
select
case px when 1 then id else '' end as ID ,
case px when 1 then TYPE else '' end as TYPE,length
from
(select px=row_number()over(partition by id order by getdate()),* from……
作者: geniuswjt 发布时间: 2011-12-05
create table tb(ID varchar(10),TYPE varchar(10),length decimal(10,2)) insert into tb select '5309622','DT',30.00 insert into tb select '8002619','BR',15.00 insert into tb select '1002619','CO',30.00 insert into tb select '1002619','BR',30.00 go ;with c1 as( select row_number()over(order by (select 1))rn,id,'CA100' as col from (select distinct id from tb)t ),c2 as( select a.rn,b.type,convert(varchar(10),b.length)col from c1 a inner join tb b on a.id=b.id ) select * from c1 union all select * from c2 order by rn /* -------------------- ---------- ---------- 1 1002619 CA100 1 CO 30.00 1 BR 30.00 2 5309622 CA100 2 DT 30.00 3 BR 15.00 3 8002619 CA100 (7 行受影响) */ go drop table tb
作者: qianjin036a 发布时间: 2011-12-05
create table tb(ID varchar(10),TYPE varchar(10),length decimal(10,2)) insert into tb select '5309622','DT',30.00 insert into tb select '8002619','BR',15.00 insert into tb select '1002619','CO',30.00 insert into tb select '1002619','BR',30.00 go ;with c1 as( select row_number()over(order by (select 1))rn,id,'CA100' as col from (select distinct id from tb)t ),c2 as( select a.rn,b.type,convert(varchar(10),b.length)col from c1 a inner join tb b on a.id=b.id ) select * from c1 union all select * from c2 order by rn,col desc /* rn id col -------------------- ---------- ---------- 1 1002619 CA100 1 CO 30.00 1 BR 30.00 2 5309622 CA100 2 DT 30.00 3 8002619 CA100 3 BR 15.00 (7 行受影响) */ go drop table tb
作者: qianjin036a 发布时间: 2011-12-05
作者: myselfff 发布时间: 2011-12-05
select id,'ca001'+char(10)+[type],length from tb
作者: myselfff 发布时间: 2011-12-05
from
(
select id,type,length,0 as orderid from tablename
union all
select distinct id,id,null,1 as orderid from tablename
)a order by id,orderid desc
作者: maoxinrongkeke 发布时间: 2011-12-05
select type,length
from
(
select id,type,length,0 as orderid from tablename
union all
select distinct id,id,null,1 as orderid from tablename
)a order by id,orderid desc
select type,length
from
(
select id,type,length,0 as orderid from tablename
union all
select distinct id,id,'固定值',1 as orderid from tablename
)a order by id,orderid desc
作者: maoxinrongkeke 发布时间: 2011-12-05
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28