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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -