当前位置: 代码迷 >> Sql Server >> 关于数据库表结构的操作,该怎么解决
  详细解决方案

关于数据库表结构的操作,该怎么解决

热度:28   发布时间:2016-04-27 13:28:19.0
关于数据库表结构的操作
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


------解决方案--------------------
SQL code
select ProductSN,max(col1) col1,max(col2) col2,max(col3) col3,...from tbgroup by ProductSN
------解决方案--------------------
SQL code
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))goinsert into tb  select 'A8319050032411501784',NULL, NULL ,NULL, NULL, NULL, NULL  union allselect 'A8319050032411501784',NULL,NULL, NULL, NULL ,NULL ,52.1600 union allselect 'A8319050032411501784',NULL, NULL, NULL ,NULL, 106.8700, NULL union allselect 'A8319050032411501784',NULL, NULL, NULL, 25.3600 ,NULL, NULL union allselect 'A8319050032411501784',NULL ,NULL ,23.3800, NULL, NULL, NULL union allselect 'A8319050032411501784',19.5200, 20.4100, NULL, NULL ,NULL, NULLgoselect 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_816from tbgroup by ProductSN/*ProductSN    Gain_min    Gain_max    VSWR_ANT_879    VSWR_Rx    F_ANT_Rx_20    F_ANT_Rx_816A8319050032411501784    19.520000    20.410000    23.380000    25.360000    106.870000    52.160000*/
  相关解决方案