tsql - SQL server random row for each unique result in column -
i have table contains multiple colleague names , sales transactions. @ end of day colleague may have had 100 sale records, need pick 1 @ random each colleague
for example if there 100 colleagues working day result give 1 random record each colleague, returning 100 in total
i have looked @ newid() can't figure out how return 1 record per colleague
you can try this:
with summary ( select o.id, o.client, o.ammount, row_number() over(partition o.id order newid()) rn orders o) select s.* summary s s.rn = 1
Comments
Post a Comment