Answer the question
In order to leave comments, you need to log in
How to group?
There is a table like [Date],[Time],[Name],[IP], which registers user logins on the PC.
For 1 day, a user can log in several times from different PCs. The task is to pull out only the first entries from the list.
With Toaster, there is already a script that pulls this set, but without [IP]
select dateadd(day, datediff(day, 0, CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 0) [Date], convert (char(8), min(CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 108) [Time],
[Name]
from [OVB].[dbo].[Logon]
group by dateadd(day, datediff(day, 0, CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 0), [Name]
order by [Name],[Date]
select dateadd(day, datediff(day, 0, CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 0) [Date], convert (char(8), min(CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 108) [Time], [Name], [IP]
from [OVB].[dbo].[Logon]
group by dateadd(day, datediff(day, 0, CONVERT(datetime, LEFT(CONVERT(VARCHAR, [Date]+' '+[Time], 103), 19))), 0), [Name], [IP]
order by [Name],[Date]
Answer the question
In order to leave comments, you need to log in
SELECT *
FROM Logon
JOIN
(
SELECT [Date] D, MIN([Time]) T
FROM Logon
GROUP BY [Date]
) X
ON [Date]=D AND [Time]=T
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question