I'm trying to set up a kind of a bid thing, where the top 5 respondents receive a prize. I was hoping to use SQL to get the top 5, but I can't remove duplicate bidders and only take their top bid. I wanted to do something like this:
=QUERY(range, "SELECT timestamp, bid, DISTINCT name, department ORDER BY bid DESC LIMIT 5")But DISTINCT doesn't work in Google Sheets. Any idea as to what I should do in this situation?
Here is my dummy data set (ignore the timestamps):
| Timestamp | Bid ($) | Name | Department |
|---|---|---|---|
| 2/16/2021 10:45:07 | 18 | Jim | Accounting |
| 2/16/2021 9:42:40 | 22 | Bob | Accounting |
| 2/16/2021 9:26:15 | 21 | Samantha | Sales |
| 2/16/2021 9:26:15 | 30 | Jim | Accounting |
| 2/16/2021 10:45:07 | 43 | Jim | Accounting |
| 2/16/2021 9:42:40 | 23 | Susan | Engineering |
| 2/16/2021 9:26:15 | 45 | Susan | Engineering |
| 2/16/2021 9:26:15 | 26 | Alex | HR |
| 2/16/2021 10:45:07 | 12 | Geoff | Sales |
| 2/16/2021 9:42:40 | 12 | Sarah | Sales |
This is my desired outcome:
| Timestamp | Bid ($) | Name | Department |
|---|---|---|---|
| 2/16/2021 9:26:15 | 45 | Susan | Engineering |
| 2/16/2021 10:45:07 | 43 | Jim | Accounting |
| 2/16/2021 9:26:15 | 26 | Alex | HR |
| 2/16/2021 9:42:40 | 22 | Bob | Accounting |
| 2/16/2021 9:26:15 | 21 | Samantha | Sales |
This is what I have so far. You can see that Jim and Susan are in the table twice and that Bob and Samantha have missed out on placing as a result of this.Using the query:
=QUERY(A3:D12, "SELECT A, B, C, D ORDER BY B DESC LIMIT 5")| Timestamp | Bid ($) | Name | Department |
|---|---|---|---|
| 2/16/2021 9:26:15 | 45 | Susan | Engineering |
| 2/16/2021 10:45:07 | 43 | Jim | Accounting |
| 2/16/2021 9:26:15 | 30 | Jim | Accounting |
| 2/16/2021 9:26:15 | 26 | Alex | HR |
| 2/16/2021 9:42:40 | 23 | Susan | Engineering |