Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

group by min and max query

I am trying to write a query based on users home drives. We have imported a huge CSV inventory of data into an MSSQL, which is basically an inventory of all files each user has within their H drive of which there are over 3000 users and almost 1.4 million files stored between them. I am trying to 'group by' the username, and then get a min and max date (what we would use in Access), of a field called LastWriteTime (type date/time) based one each users home drive, to basically show 'for this users H:\drive this was the first LastWriteTime recorded, and this was the last LastWriteTime recorded. Having the stats per home drive folder would be perfect. So something like...


user - FirstModified - LastModified
\\server\share\user1 - 01/01/2019 - 22/11/2019
\\server\share\user2 - 01/06/2019 - 10/11/2019

The issue/challenge is, the field which represents folder/path (called FullName, type nvarchar(max)) I essentially need to use a segment of the text, e .g. \\server\share\username\ as the unique identifier on which to produce stats on. As entries lower down the inventory will be in format \\server\share\username\folder1\worddoc.docx etc. I am not sure if this would need to be done in multiple stages, but the consistent thing is, the username part would always be that before the  5th back slash, or we could even use the content between the 4th and 5th back slash, e.g. \\server\share\username\ (as everyone's H drive is unique and based upon their AD login name). Given the size of the data I cannot easily do any form of text to columns manipulation in another tool like Excel to extract the username in order to do some min/max date stats, hence we had to get the data into MSSQL in the first place.
Avatar of PortletPaul
PortletPaul
Flag of Australia image

sample of raw data would help (just a few rows for just a few users)

what version of mssql?
can you use string_split() ?
Avatar of Pau Lo
Pau Lo

ASKER

MSSQL 2016 SP2.

For some random data, its essentially a database based upon the output of this AD command, just select a directory and its the same data its just we have imported it into MSSQL to get some stats on it:

Get-childitem -path “\\server\share” -recurse | select fullname,name,attributes,lastwritetime,creationtime,LastAccessTime, length | Export-Csv c:\users\me\desktop\inventory.csv –NoTypeInformation

Open in new window


Not familiar with string split to be honest.
ASKER CERTIFIED SOLUTION
Avatar of PortletPaul
PortletPaul
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial