sql server - SQL Group by date only choose 1 record -
i trying return 1 record following table not working. return multiple record.please advise, thank you
i suspect problem groupby
createdate firstname eventid 2013-05-13 18:11:35.187 jack 0cd7b08a-0eaf-4515-9de1-00fc6db29a61 2013-05-13 18:11:35.310 paul 16a584d5-e9b7-4617-8dc9-089c628e0ed5 2013-05-13 20:14:33.863 craig aaa21035-1377-443d-9bee-0c0761534803
here sql query result above:
select max (createdate) create_date, firstname ,eventid sessionsevents trn='0391588' group firstname , trn, eventid
its group data firstname after trn , after eventid trn persent in query , should same in resultset , firstname, eventid columns have not same data grouping , rows separate in resultset if need maximum create date should use top
keyword sql server:
select top 1 max (createdate) create_date, firstname ,eventid sessionsevents trn='0391588' group firstname , trn, eventid
Comments
Post a Comment