Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(+2)

What is a good way to order a query by two values? I’m making a flash-card deck and want to sort the cards based on some “score” I calculate, and if they’re equal fall back on the time they were last accessed. Tupling the values is not an option, since anything but an integer will be converted to string for comparison. I could just do that with nested queries, but that doesn’t feel very good.

(+1)

Well, you could've formatted columns together to form keys with a natural lexicographic comparison, but that's horrible.

I made a tweak to the behavior of "orderby" which borrows from how the "grade" operators work in K: lists are now given a lexicographic comparison, so tupling will now work. The "join" operator will zip together columns for this purpose. As a contrived example:

    e:insert c:""split"ABBBABABABABAAABA" n:(7,7,2,4,4,0,3,4,2,0,9,7,4,6,8,2,3) into 0 
    select c n orderby (c join n) asc from e
+-----+---+
| c   | n |
+-----+---+
| "A" | 2 |
| "A" | 3 |
| "A" | 3 |
| "A" | 4 |
| "A" | 4 |
| "A" | 6 |
| "A" | 7 |
| "A" | 8 |
| "A" | 9 |
| "B" | 0 |
| "B" | 0 |
| "B" | 2 |
| "B" | 2 |
| "B" | 4 |
| "B" | 4 |
| "B" | 7 |
| "B" | 7 |
+-----+---+