0

So I have a table that looks like this:

LocationID, License, Rank

Each location can have multiple licenses and they're ordered by rank.

My goal is to make a query that lists them like this:

LocationID, License1 (Rank 1), License 2 (Rank 2), License 3 (Rank 3)

but I am not sure how to query like this.

I have attempted to make like 15 views that store the values by rank however when joining on these views, the execution time rises like crazy.

Any advice would be great!

EDIT: So I have pivoted based on the comments, and I have a result set that looks like this:

Location ID:
1,                 value1, NULL, NULL.
1,                 NULL, value2, NULL,
1,                 NULL, NULL, value3

I want to query like this.

LocationID, Value1, Value2, Value3. 
Justin Le
  • 673
  • 1
  • 8
  • 24
  • Instead of joining after you rank, instead [like at this question](https://stackoverflow.com/questions/15931607/convert-rows-to-columns-using-pivot-in-sql-server). [Or here for a more dynamic list of result columns](https://stackoverflow.com/questions/10404348/sql-server-dynamic-pivot-query) – JNevill Sep 17 '18 at 20:37
  • I have modified my question @JNevill – Justin Le Sep 18 '18 at 14:45

1 Answers1

0
Select
MAX(value)
,MAX(value2)
,MAX(Value3)
FROM myTable
GROUP BY values
Justin Le
  • 673
  • 1
  • 8
  • 24