我想提取每日销售数据,它会显示每天开立的每个新帐户的单独行。我使用以下代码尝试了这一点,但是,我继续获取重复记录,并且不确定如何阻止这种情况发生。
该表格包含以下内容:
[AccountID]
[ID]
[AccountNumber]
[OpenDate]
[CloseDate]
[ProductType]
SELECT
[Account].[ID],
[ProdutType],
MIN ([OpenDate]) AS OpenDate,
MIN [CloseDate] AS CloseDate
FROM
[Account]
GROUP BY
[ID],
[ProductType]
答案 0 :(得分:0)
请尝试使用此语法,根据您的查询进行调整。我需要看到结果
With cte as
(
select
[AccountID],
[ID],
[AccountNumber],
[OpenDate],
[CloseDate],
[ProductType],
ROW_NUMBER() OVER(PARTITION BY [AccountID] ORDER BY [OpenDate] ASC) as [FileCount]
From [Account]
)
select * from cte
Group By [AccountID],
[ID],
[AccountNumber],
[OpenDate],
[CloseDate],
[ProductType]