Jump to content
UBot Underground

How To Sort Table (Including Headers) By Column A Then Column B?


Recommended Posts

Hi all,

 

I want to sort a table which has a header, to be first sorted by say column A then column B, as one would do in Excel. Could not think of another solution given that for example putting each column (a and B) into a list and then sorting would obviously not be accurate

Link to post
Share on other sites

I'll leave it open and leave a solution as well for others who don't know how to use Sqlite, the Table Commands plugin comes with Ubot:

clear table(&data)
set table cell(&data,0,0,"b")
set table cell(&data,0,1,1)
set table cell(&data,1,0,"a")
set table cell(&data,1,1,5)
plugin command("TableCommands.dll", "sort table", &data, 0)
alert(&data)
plugin command("TableCommands.dll", "sort table", &data, 1)
alert(&data)
  • Like 2
Link to post
Share on other sites

I should have been more precise (screenshot did not work.) : I wanted to sort by Column A THEN Column B, so in that order.

 

Imagine an Example of Say TV Series, You have Season 1, Season 2....but then each season has Episode 1 , 2,3....

 

So the output should be 

 

Season 1  , 1

Season 1 , 2

Season 2, 1

Season 2 , 2

 

But as you can see fromt he example below it just sorts column A, then it sorts B isolated now in the same process. Hope that makes more sense now

clear table(&data)
set table cell(&data,0,0,"Season 1")
set table cell(&data,0,1,2)
set table cell(&data,1,0,"Season 1")
set table cell(&data,1,1,1)
set table cell(&data,2,0,"Season 2")
set table cell(&data,2,1,2)
set table cell(&data,3,0,"Season 2")
set table cell(&data,3,1,1)
plugin command("TableCommands.dll", "sort table", &data, 0)
alert(&data)
plugin command("TableCommands.dll", "sort table", &data, 1)
alert(&data)

I tried working on a solution just using tables and lists, but realized it turned into way too much effort and I will rather just use Ayman's SQLite plugin.

 

The above example is very simple s could likely be solved by adding another sort, But what If I need to sot by A,B,C and then add in descending vs. regular ascending (for letter and numbers)...

Link to post
Share on other sites

You can extract each season into its own table and then sort those tables and add them together but if you already have a solution then that's probably better.

 

But basically it would involve first sorting by season, then using the table search function to find the row index of the start of the next season. Extracting the current season into a table, sort that table and then go to the next.

Link to post
Share on other sites

I figured it is easier to use sql queries for that , as I tried it earlier with say 3 columns. Also , given that this example was pretty easy, but with 3 columns some could be strings, others numbers that would need to be sorted descending etc... 

 

It just seemed to be saving way more time just using sql for this. Appreciate the replies though !

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...