itsmehar
asked on
SQL Query Help
Below is the table structure:
This below query works but was just wondering if there is a better way of writing this without having to put ClientID, ClientName and other fields that I want to retrieve in the order by clause because they are varchar fields and there may be slight variation in those fields especially in the ClientName field.
Number ClientID ClientName PltVersion OptCt DateTimeStarted DateTimeFZ RunStatus
10819259 1450 abc x1 0 6/1/2014 0:03:35 6/1/2014 0:56:06 Success
10819259 1450 abc x1 0 6/1/2014 0:03:35 6/1/2014 0:56:06 Success
10819260 1450 xyz x1 1 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 3000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 1 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 0 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819260 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:14:03 Success
10819261 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:34:07 Success
10819261 1450 xyz x1 4000 6/1/2014 0:03:36 6/1/2014 2:34:07 Success
This below query works but was just wondering if there is a better way of writing this without having to put ClientID, ClientName and other fields that I want to retrieve in the order by clause because they are varchar fields and there may be slight variation in those fields especially in the ClientName field.
SELECT Distinct Number, ClientID, ClientName, PltVer, MIN(DateTimeStarted), MAX(DateTimeFZ), SUM(Images) ImageCt
FROM [table_name]
WHERE
(DateTimeStarted BETWEEN '2014-09-29' AND '2014-10-05') AND
RunStatus IN ('xxx', ''yyy, 'etc')
GROUP BY RunNumber, ClientID, ClientName, PltVersion
ORDER BY RunNumber
ASKER
Is the OVER PARTITION clause supported in SQL2008?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
doesnt work for me
Instead of accepting my answer that doesn't work for you I suggest you keep the question open by allowing other experts look into it
Open in new window
As you can see I have completely removed the GROUP BY clause as it is not required here.Alternatively you can use the aggregate functions on other columns, like this:
Open in new window