B字段有重复的,A没重复,其他不管
剔除B中重复的数据,保留对应A数据值较小的一个
返回符合条件的行存入另一张表
存入的字段要全,不只有AB
14 个解决方案
#1
既然你都描述出来了,我想应该能写出来吧。
#2
INSERT NEWTB SELECT * FROM TB T WHERE B=(SELECT MIN(B) FROM TB WHERE A=T.A)
#3
delete tb where exists(select 1 from tb t where b=tb.b and a>tb.a)
#4
SELECT * INTO NEWTB FROM TB T WHERE B=(SELECT MIN(B) FROM TB WHERE A=T.A)
#5
insert t2
select * from t1 where not exists(select 1 from t1 a where a.b=t1.b and a.a<t1.a)
#6
insert
t2
select
*
from
t1
where
not exists(select 1 from t1 a where a.b=t1.b and a.a<t1.a)
#7
SET IDENTITY_INSERT RPT_DayStat_COD ON
INSERT dbo.RPT_DayStat_COD
SELECT * FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
SET IDENTITY_INSERT RPT_DayStat_COD OFF
这是我写的,@TempTable1是一张临时表,存放的是剔除出来的AB字段
然后通过与原表INNER JOIN 返回符合的数据行
但是一直报错
消息 8101,级别 16,状态 1,过程 UP_Report_COD_Day,第 102 行
仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'dbo.RPT_DayStat_COD'中的标识列指定显式值。
#8
INSERT dbo.RPT_DayStat_COD(除自增列的所有列名)
SELECT 列名...FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
SELECT 列名...FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
#9
#10
INSERT dbo.RPT_DayStat_COD(portId, tstamp, ZAD_DATA1, ZAD_DATA2, ZAD_DATA3, ZAD_DATA4, ZAD_DATA5, ZAD_DATA6, ZAD_DATA7, ZAD_DATA8, ZAD_DATA9,
ZAD_DATA10, ZAD_DATA11, ZAD_DATA12, ZAD_DATA13, ZAD_DATA14, ZAD_DATA15, ZAD_DATA16, ZAD_DATA17, ZAD_DATA18, ZAD_DATA19,
ZAD_DATA20, ZAD_DATA21, ZAD_DATA22, ZAD_DATA23, ZAD_DATA24, ZAD_DATA25, ZAD_DATA26, ZAD_DATA27, ZAD_DATA28, ZAD_DATA29,
ZAD_DATA30, ZAD_DATA31, ZAD_DATA32, ZAD_DATA33, ZAD_DATA34, ZAD_DATA35, ZAD_DATA36, ZAD_DATA37, ZAD_DATA38, ZAD_DATA39,
ZAD_DATA40, ZAD_DATA41, ZAD_DATA42, ZAD_DATA43, ZAD_DATA44, ZAD_DATA45, ZAD_DATA46, ZAD_DATA47, ZAD_DATA48, ZAD_DATA49,
ZAD_DATA50)
SELECT portId, tstamp, ZAD_DATA1, ZAD_DATA2, ZAD_DATA3, ZAD_DATA4, ZAD_DATA5, ZAD_DATA6, ZAD_DATA7, ZAD_DATA8, ZAD_DATA9,
ZAD_DATA10, ZAD_DATA11, ZAD_DATA12, ZAD_DATA13, ZAD_DATA14, ZAD_DATA15, ZAD_DATA16, ZAD_DATA17, ZAD_DATA18, ZAD_DATA19,
ZAD_DATA20, ZAD_DATA21, ZAD_DATA22, ZAD_DATA23, ZAD_DATA24, ZAD_DATA25, ZAD_DATA26, ZAD_DATA27, ZAD_DATA28, ZAD_DATA29,
ZAD_DATA30, ZAD_DATA31, ZAD_DATA32, ZAD_DATA33, ZAD_DATA34, ZAD_DATA35, ZAD_DATA36, ZAD_DATA37, ZAD_DATA38, ZAD_DATA39,
ZAD_DATA40, ZAD_DATA41, ZAD_DATA42, ZAD_DATA43, ZAD_DATA44, ZAD_DATA45, ZAD_DATA46, ZAD_DATA47, ZAD_DATA48, ZAD_DATA49,
ZAD_DATA50
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
数据库字段对应没错
消息 209,级别 16,状态 1,过程 UP_Report_COD_Day,第 107 行
列名 'tstamp' 不明确。
消息 209,级别 16,状态 1,过程 UP_Report_COD_Day,第 107 行
列名 'ZAD_DATA5' 不明确。
这是什么意思...
#11
如果两表都有相同列名,请指定表名
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
#12
DECLARE @TempTable1 TABLE(tstamp datetime,ZAD_DATA5 float)
临时表也没错
临时表也没错
#13
HOHO,多谢多谢,原来跟临时表字段不明确~~~
#14
解决请即时结帖
#1
既然你都描述出来了,我想应该能写出来吧。
#2
INSERT NEWTB SELECT * FROM TB T WHERE B=(SELECT MIN(B) FROM TB WHERE A=T.A)
#3
delete tb where exists(select 1 from tb t where b=tb.b and a>tb.a)
#4
SELECT * INTO NEWTB FROM TB T WHERE B=(SELECT MIN(B) FROM TB WHERE A=T.A)
#5
insert t2
select * from t1 where not exists(select 1 from t1 a where a.b=t1.b and a.a<t1.a)
#6
insert
t2
select
*
from
t1
where
not exists(select 1 from t1 a where a.b=t1.b and a.a<t1.a)
#7
SET IDENTITY_INSERT RPT_DayStat_COD ON
INSERT dbo.RPT_DayStat_COD
SELECT * FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
SET IDENTITY_INSERT RPT_DayStat_COD OFF
这是我写的,@TempTable1是一张临时表,存放的是剔除出来的AB字段
然后通过与原表INNER JOIN 返回符合的数据行
但是一直报错
消息 8101,级别 16,状态 1,过程 UP_Report_COD_Day,第 102 行
仅当使用了列列表并且 IDENTITY_INSERT 为 ON 时,才能为表'dbo.RPT_DayStat_COD'中的标识列指定显式值。
#8
INSERT dbo.RPT_DayStat_COD(除自增列的所有列名)
SELECT 列名...FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
SELECT 列名...FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
#9
#10
INSERT dbo.RPT_DayStat_COD(portId, tstamp, ZAD_DATA1, ZAD_DATA2, ZAD_DATA3, ZAD_DATA4, ZAD_DATA5, ZAD_DATA6, ZAD_DATA7, ZAD_DATA8, ZAD_DATA9,
ZAD_DATA10, ZAD_DATA11, ZAD_DATA12, ZAD_DATA13, ZAD_DATA14, ZAD_DATA15, ZAD_DATA16, ZAD_DATA17, ZAD_DATA18, ZAD_DATA19,
ZAD_DATA20, ZAD_DATA21, ZAD_DATA22, ZAD_DATA23, ZAD_DATA24, ZAD_DATA25, ZAD_DATA26, ZAD_DATA27, ZAD_DATA28, ZAD_DATA29,
ZAD_DATA30, ZAD_DATA31, ZAD_DATA32, ZAD_DATA33, ZAD_DATA34, ZAD_DATA35, ZAD_DATA36, ZAD_DATA37, ZAD_DATA38, ZAD_DATA39,
ZAD_DATA40, ZAD_DATA41, ZAD_DATA42, ZAD_DATA43, ZAD_DATA44, ZAD_DATA45, ZAD_DATA46, ZAD_DATA47, ZAD_DATA48, ZAD_DATA49,
ZAD_DATA50)
SELECT portId, tstamp, ZAD_DATA1, ZAD_DATA2, ZAD_DATA3, ZAD_DATA4, ZAD_DATA5, ZAD_DATA6, ZAD_DATA7, ZAD_DATA8, ZAD_DATA9,
ZAD_DATA10, ZAD_DATA11, ZAD_DATA12, ZAD_DATA13, ZAD_DATA14, ZAD_DATA15, ZAD_DATA16, ZAD_DATA17, ZAD_DATA18, ZAD_DATA19,
ZAD_DATA20, ZAD_DATA21, ZAD_DATA22, ZAD_DATA23, ZAD_DATA24, ZAD_DATA25, ZAD_DATA26, ZAD_DATA27, ZAD_DATA28, ZAD_DATA29,
ZAD_DATA30, ZAD_DATA31, ZAD_DATA32, ZAD_DATA33, ZAD_DATA34, ZAD_DATA35, ZAD_DATA36, ZAD_DATA37, ZAD_DATA38, ZAD_DATA39,
ZAD_DATA40, ZAD_DATA41, ZAD_DATA42, ZAD_DATA43, ZAD_DATA44, ZAD_DATA45, ZAD_DATA46, ZAD_DATA47, ZAD_DATA48, ZAD_DATA49,
ZAD_DATA50
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
ON m.tstamp=f.tstamp
数据库字段对应没错
消息 209,级别 16,状态 1,过程 UP_Report_COD_Day,第 107 行
列名 'tstamp' 不明确。
消息 209,级别 16,状态 1,过程 UP_Report_COD_Day,第 107 行
列名 'ZAD_DATA5' 不明确。
这是什么意思...
#11
如果两表都有相同列名,请指定表名
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
FROM dbo.ADT_Infectant m INNER JOIN @TempTable1 f
#12
DECLARE @TempTable1 TABLE(tstamp datetime,ZAD_DATA5 float)
临时表也没错
临时表也没错
#13
HOHO,多谢多谢,原来跟临时表字段不明确~~~
#14
解决请即时结帖