Jump to content

Nasevz

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Nasevz

  1. Your query solved the problem, thank you.
  2. If I understand your query correctly, you are suggesting me to have two identical tables with different names?
  3. The problem is that I would like whole row with all columns for each computename where max(logontime) has highest value and max(logofftime) is not necessarily in the same row with max(logontime) because sometimes workstations fail to write logofftime (reset, power failure ...). Maybe it can be written with subqueries, but I am not very experianced in SQL.Thank you for trying to help me.
  4. From previous message: select computername, max(logontime) from log group by computernamewould return the right values, but I need a whole row (including userid and logofftime), and if I add userID and logofftime to select statemet, they also must be either in agregate function or in a group by clause. I dont know if it is an agregate function that returns the value retreived by finding the max value of another column (return logofftime and userID from the row where logontime has maximum value) BTW grouping by computername implys distinct computernames, so with or without distinct, the result is the same.
  5. This is the error message from the select statementMsg 8120, Level 16, State 1, Line 1Column 'log.computername' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 145, Level 15, State 1, Line 1ORDER BY items must appear in the select list if SELECT DISTINCT is specified.1. distinct is applyed to whole row, not on computername only, so 'distinct computername, logontime' would return all distinct combinations of them.2. MAX(logontime) returns the maximum value of logontime for whole table and it is only one.If distinct computername returns 20 computernames and MAX(logontime) only one, the right rows can't be returnedselect computername, max(logontime) from log group by computernamewould return the right values, but I need a whole row (including userid and logofftime), and if I add userID and logofftime to select statemet, they also must be either in agregate function or in a group by clause. I dont know if it is an agregate function that returns the value retreived by finding the max value of another column (return logofftime and userID from the row where logontime has maximum value)
  6. This would select all logontimes for all computers because all logontimes would most likely be different. I would like only the logontime that has the highest value for each computer.The computer names in the table are repeated many times (each time somebody logs on on that computer and there are many computers, not one) and I would like only the last logons for all computers.
  7. My table has this columns:rowId, computerName, logonTime, logoffTime, userNameI would like to select a row for each computerName where logonTime has highest value (To see rows where last logon happened for each computer).I am trying something like SELECT computerName, max(logonTime), logoffTime, userName from log GROUP BY computerName HAVING logonTime=max(logonTime) ???but I need to get row where max(logonTime) appears in each group (computerName).Can somebody help me?
×
×
  • Create New...