当两个最后日期之间的某些列相同时删除行

时间:2016-04-27 20:14:07

标签: sql-server-2008 common-table-expression

我有以下表格和数据:

(由于某种原因,SQL Fiddle现在不能使用SQL Server rigth)

CREATE TABLE [dbo].[BFBMT02_SALDOS_BILLETERA](
    [T02_FECHA] [varchar](64) NOT NULL,
    [T02_ACCOUNTID] [varchar](230) NOT NULL,
    [T02_ACCOUNTHOLDERID] [varchar](230) NOT NULL,
    [T02_MSISDN] [varchar](230) NULL,
    [T02_PROFILE] [varchar](230) NOT NULL,
    [T02_ACCOUNTTYPE] [varchar](20) NOT NULL,
    [T02_BALANCE] [numeric](20, 2) NOT NULL,
    [T02_CURRENCY] [char](3) NOT NULL,
    [T02_FREGISTRO] [datetime] NOT NULL,
 CONSTRAINT [PK_BFBMT02_SALDOS_BILLETERA] PRIMARY KEY CLUSTERED 
(
    [T02_FECHA] ASC,
    [T02_ACCOUNTID] ASC
)
) ON [PRIMARY]

GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160408_000000', N'1045949', N'79851', N'51994899395', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(0.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF9590 AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160408_000000', N'1046410', N'87614', N'51949080301', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(2.50 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF9590 AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160408_000000', N'1049187', N'77940', N'51997090440', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(0.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF9590 AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160411_000000', N'1045949', N'79851', N'51994899395', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(0.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF95AC AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160411_000000', N'1049187', N'77940', N'51997090440', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(1.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF95AC AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160412_000000', N'1045949', N'79851', N'51994899395', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(0.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF95C6 AS DateTime))
GO
INSERT [dbo].[BFBMT02_SALDOS_BILLETERA] ([T02_FECHA], [T02_ACCOUNTID], [T02_ACCOUNTHOLDERID], [T02_MSISDN], [T02_PROFILE], [T02_ACCOUNTTYPE], [T02_BALANCE], [T02_CURRENCY], [T02_FREGISTRO]) VALUES (N'20160412_000000', N'1049187', N'77940', N'51997090440', N'BFinanciero Normal Account Profile', N'Mobile Money', CAST(0.00 AS Numeric(20, 2)), N'PEN', CAST(0x0000A5F500EF95C6 AS DateTime))
GO

我希望在T02_BALANCE列中的值未更改时擦除所有行 在日期,欲望输出由此查询表示:

SELECT * FROM
(SELECT ROW_NUMBER() OVER(ORDER BY T02_FECHA) AS T,* FROm  BFBMT02_SALDOS_BILLETERA ) TB WHERE T IN (1,2,3,5,7)

0 个答案:

没有答案