Google sheets query Order by

49 Views Asked by At

I have a query that selects * from column A, column B, column C.

Column A is dates. B is income. C is debts.

How do I order by A, B so B entries return before C entries when they have the same date?

Jan1 income
Jan1 income
jan1           debts
Jan2 income
Jan2           debts
Jan2           debts
Etc

Sorry I'm on my phone so was going to add a screenshot that would clarify much easier but it is saying the image is to large lol ..um this is a site about coding and they can't run a simple optimization script?

2

There are 2 best solutions below

1
Mureinik On

You can union all two queries, one from B and one from C, and add a fictitious column just for the ordering:

SELECT   a, b
FROM     (SELECT a, b, 1 AS ordering_col
          FROM   mytable
          ORDER BY
          SELECT a, c, 2 AS ordering_col
          FROM   mytable) t
ORDER BY a ASC, ordering_col ASC
0
Googlegeek On

I figured it out.

Order by Col1,Col2 DESC