Skip to content
Advertisement

Can repeating query be saved?

In my Python / Sqlite program, I am running queries like this

JavaScript

So the “basic” query is the same, and the rows Sqlite gathers are the same, but because of the different grouping , I have to run the same query multiple times.

I wonder if there is a way to achieve the same output more effectively, ie. run the query only once?

Advertisement

Answer

In each of your subqueries, although you are using GROUP BY, you are not doing any aggregation, so I think that all you want is to count the distinct aX for each case.

You can do this in a single query and return all the counters as different columns:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement