关于数据库表结构的操作

fang1229 2012-04-11 05:46:49
ProductSN Gain_min Gain_max VSWR_ANT_879 VSWR_Rx F_ANT_Rx_20 F_ANT_Rx_816
A8319050032411501784 NULL NULL NULL NULL NULL NULL
A8319050032411501784 NULL NULL NULL NULL NULL 52.1600
A8319050032411501784 NULL NULL NULL NULL 106.8700 NULL
A8319050032411501784 NULL NULL NULL 25.3600 NULL NULL
A8319050032411501784 NULL NULL 23.3800 NULL NULL NULL
A8319050032411501784 19.5200 20.4100 NULL NULL NULL NULL



上面是我的表结构 想把它变成一行(像下面的一样) 有什么办法没

ProductSN Gain_min Gain_max VSWR_ANT_879 VSWR_Rx F_ANT_Rx_20 F_ANT_Rx_816
A8319050032411501784 19.5200 20.4100 23.3800 25.3600 106.8700 52.1600
...全文
70 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Felixzhaowenzhong 2012-04-11
  • 打赏
  • 举报
回复
create table tb(ProductSN varchar(120),Gain_min decimal(18,6), Gain_max decimal(18,6),VSWR_ANT_879 decimal(18,6),VSWR_Rx decimal(18,6),F_ANT_Rx_20 decimal(18,6), F_ANT_Rx_816 decimal(18,6))
go
insert into tb
select 'A8319050032411501784',NULL, NULL ,NULL, NULL, NULL, NULL union all
select 'A8319050032411501784',NULL,NULL, NULL, NULL ,NULL ,52.1600 union all
select 'A8319050032411501784',NULL, NULL, NULL ,NULL, 106.8700, NULL union all
select 'A8319050032411501784',NULL, NULL, NULL, 25.3600 ,NULL, NULL union all
select 'A8319050032411501784',NULL ,NULL ,23.3800, NULL, NULL, NULL union all
select 'A8319050032411501784',19.5200, 20.4100, NULL, NULL ,NULL, NULL
go
select ProductSN,max(Gain_min) Gain_min,max(Gain_max) Gain_max,max(VSWR_ANT_879) VSWR_ANT_879,max(VSWR_Rx) VSWR_Rx,max(F_ANT_Rx_20) F_ANT_Rx_20,max(F_ANT_Rx_816) F_ANT_Rx_816
from tb
group by ProductSN
/*
ProductSN Gain_min Gain_max VSWR_ANT_879 VSWR_Rx F_ANT_Rx_20 F_ANT_Rx_816
A8319050032411501784 19.520000 20.410000 23.380000 25.360000 106.870000 52.160000
*/
AcHerat 2012-04-11
  • 打赏
  • 举报
回复

select ProductSN,max(col1) col1,max(col2) col2,max(col3) col3,...
from tb
group by ProductSN

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧