I’m not entirely sure how to phrase this question simply, so I will be taking suggestions to rename my question. I apologize in advance for how idiotic this question might seem, but I’m having one of those brain-fart moments where I just can’t wrap my head around it.
The table I have in mind is created by:
CREATE TABLE STRUCTURES (X INT(4),Z INT(4),TYPE CHAR(1),SEED_ID BIGINT);
The question is, how do I find the maximum amount of entries for which TYPE=’V’ and SEED_ID is the same? Let’s call this number MAX_TYPE_V.
To clarify, I’m using the query:
SELECT SEED_ID
FROM STRUCTURES
WHERE TYPE='V'
GROUP BY SEED_ID
HAVING COUNT(SEED_ID)=MAX_TYPE_V;
but I don’t know how to find MAX_TYPE_V to plug into aforementioned query, so my workaround is to try the query for MAX_TYPE_V from 1 to 2^31-1 until the query fails for some number i, which means that i-1 is my maximum, but this is very time-consuming and quite stupid, frankly.
I’m using SQLite3, so any answers should probably tackle MySQL syntax.
1 Answer