In my Python / Sqlite program, I am running queries like this
q=SELECT COUNT(1) FROM (SELECT a1 FROM tableX WHERE freq>=1.6 AND a3='n' AND a4='y' AND a5='q' GROUP BY a1)
q=SELECT COUNT(1) FROM (SELECT a2 FROM tableX WHERE freq>=1.6 AND a3='n' AND a4='y' AND a5='q' GROUP BY a2)
q=SELECT COUNT(1) FROM (SELECT a9 FROM tableX WHERE freq>=1.6 AND a3='n' AND a4='y' AND a5='q' GROUP BY a9)
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?