Skip to content
Advertisement

SQL Server select query based on logic

I have the below table :

I need the below output table :

Priority list for the packages : T, E, B, F . Basically the logic should be as below :

  1. If multiple entries of ID is there then select the packages based on priority list
  2. If single entry, then pick it as such

Advertisement

Answer

We can use ROW_NUMBER here:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement