I'm new to Google Big Query (and Stack Overflow), mainly testing the speed at which Big Query manages to process both well-crafted and poorly-crafted queries.
I'm having difficulty with a cumbersome query that runs (slowly) on MySQL. Big Query complains about the GROUP BY contents. Here's the starting query:
SELECT nonstops.term, nonstops.lincat, nonstops.id,
MIN(
(1-((LEAST(1,minusone.catimp / nonstops.catimp) + LEAST(1,minusone.catweb / nonstops.catweb))/2))*
(1-((LEAST(1,minusone.catimp / nonstops.catimp) + LEAST(1,minusone.catweb / nonstops.catweb))/2))*
(1-((LEAST(1,minusone.catimp / nonstops.catimp) + LEAST(1,minusone.catweb / nonstops.catweb))/2))*
(nonstops.catweb * nonstops.catweb * nonstops.catimp / nonstops.fnvweb / nonstops.fnvimp)
)
AS calc FROM nonstops INNER JOIN EACH minusone ON nonstops.lincat = minusone.lincat AND nonstops.term = minusone.term
WHERE nonstops.lincat = 556 GROUP BY nonstops.term, nonstops.lincat
ORDER BY `calc` DESC
Note that "EACH" is added to the INNER JOIN as both tables are big. I have removed the dataset name to make it easier to read.
The GROUP BY is intended to return just the lowest value of the calculation that is made by the join for each term/lincat pair.
The error I get is:
(L1:62): Expression 'phrases.nonstops.id' is not present in the GROUP BY list
Which I don't want in the GROUP BY, but I've added it and I then get:
Expression 'calc
' is not present in the GROUP BY list
Which I also do not want! But if I add it I get:
(L7:1): Cannot group by an aggregate
I have looked at the documentation and searched for an answer, but no luck. Any hints or links would be most appreciated.