Hi @Shreyas Kale
The reason why you got multiple records for single date per TENETWORKID is: you have extra GROUP BY column [DeviceName] which is no need.
Since one TENETWORKID could have different records with different DeviceNames in one single date, so if you GROUP BY CAST([EDateTime] AS DATE),[TENETWORKID],[DeviceName]
you will got that issue.
Here is a solution using ROW_NUMBER:
;WITH CTE AS
(
SELECT [TENETWORKID],[DeviceName],[EDateTime]
,ROW_NUMBER()OVER(PARTITION BY CAST([EDateTime] AS DATE),[TENETWORKID] ORDER BY [EDateTime] ASC) AS RNum
FROM [PowerBI].[dbo].[PowerBI_data]
)
SELECT [TENETWORKID],[DeviceName],CAST([EDateTime] AS DATE) AccessDate
FROM CTE
WHERE RNum = 1
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.