简体   繁体   中英

Creating a Wait List in SQL

Let's Say, I have a Header Table with two Columns (Name and Date).

Paul | 10/12/2002  
Donna | 07/11/2000  
Gary | 03/14/2021

And I want to create a waitlist/que driven by oldest date first

Select * Order By Date

I can easily create a Next-Up style of que by sorting ASC or DESC on Date.

But I need to go a step further. I need to have my SELECT include a temporary column that shows what number, in the que, a person is.

So - Gary logs in and sees that he is 3'rd in line, but only sees his information.

Expected Results:

Name:  Gary     Date:  03/14/2021   Position:  3

Use the row_number() function like:

Select Name, Date, row_number() over(order by Date ASC)
from table

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM