I have an array of results which I get from SQL by using ActiveRecord::Base.connection.execute command. (I cannot use ActiveRecord queries like Object.where() because the table has no corresponding model)
I get an array as:
2800 1.7 1
2000 4.5 0
2107 3.0 0
2107 5.6 1
3435 2.3 0
3425 0.0 0
3425 1.3 0
1980 2.0 0
Now I want to sort this 2D array by the values in the 3rd column, so that all rows with a value of 1 in 3rd column move to the bottom, but want to keep all the rows with the same value in the 1st column to be together.
The resulting sorted array should look like this:
2000 4.5 0
3435 2.3 0
3425 0.0 0
3425 1.3 0
1980 2.0 0
2800 1.7 1
2107 3.0 0
2107 5.6 1
Now I know this can be done by using a sum query on the 3rd column or by using the sort_by method on the array, but I'm unable formulate a correct query. Any pointers on how to proceed will be appreciated.
ActiveRecordmodel for that table?select * from TABLE_NAME order by 3rd_COLUMNright now