I want to select all the rows of carInventory table but have the brands which has a car in some sort of blue to be first. After, the cars in each brand sorts by year.
I was trying to alter the solution that was given in this post Take precedence on a specific value from a table but I can't seem to keep the brands together after I figure out the rank
SELECT
*, RANK() over(
partition by colBrand
order by case when colColor like '%blue%' then 1 else 0 end
) RANK FROM inventoryTable Order By Rank, colBrand, colYear
Here's what the tables should look like. Starting Table
| Brand | Make | Color | Year |
|---|---|---|---|
| Toyota | Corolla | Atlantis Blue | 2015 |
| Ford | Focus | Bayside Blue | 2016 |
| Porshe | Taycan | Grey | 2019 |
| Volkswagen | Taos | Blue | 2015 |
| Volkswagen | Jetta | White | 2020 |
| Ford | Focus | Aztec Red | 2018 |
Search Result
| Brand | Make | Color | Year |
|---|---|---|---|
| Ford | Focus | Aztec Red | 2018 |
| Ford | Focus | Bayside Blue | 2016 |
| Toyota | Corolla | Atlantis Blue | 2015 |
| Volkswagen | Taos | Blue | 2020 |
| Volkswagen | Jetta | White | 2015 |
| Porshe | Taycan | Grey | 2019 |