How to do sorting of the list by default which displays tasks with sub-tasks, active tasks and closed?

Is it possible with one query to select and sort so that tasks with subtasks displayed at the top of the list, closed at the bottom, and between them active without subtasks?

Or is it better not to complicate and make three request, or to sort an array and sends it to the adapter, or when you create an array for the adapter first to upload three arrays, after the glue in the correct order?
June 14th 19 at 20:49
2 answers
June 14th 19 at 20:51
Solution
At all possible. Here it is:
SELECT *
FROM tasks
ORDER BY CASE WHEN tasks.status = "active" AND tasks.hasSub = 1 THEN 0 WHEN tasks.status = "active" THEN 1 ELSE 2 END
Thanks, I'll try. Did not know that the order can be sorted by conditions. - Clifton.Treut commented on June 14th 19 at 20:54
only in the query execution plan look. Not sure what the best use of sorting so. Much more logical to make a field and sort by it, but I think internal compiler SQL query so the query and process) - Francisco.Wisoky commented on June 14th 19 at 20:57
Tried, it works. The optimality, yet do not bother.

I have Android at the Amateur level. Write taskmanager've always searched for but never found. During use and gradually increase functionality.

If the result still get something sensible, put on the market ) - Clifton.Treut commented on June 14th 19 at 21:00
June 14th 19 at 20:53
Solution
Possible, but easier obedinet three select a Union.
Thank you. Forgot about Union. - Clifton.Treut commented on June 14th 19 at 20:56
actually in theory the relational database can reorder the results, but in practice rolls ) - Francisco.Wisoky commented on June 14th 19 at 20:59

Find more questions by tags AndroidSQL