Ok so I know it's a car forum, but some of you might be able to help, I hope!
I need to run a query that has many individual parts, but they need to be treated as a whole set on multiple rows.
Greately simplified, something like this:
Query is something like 'get me all rows as a whole group that match the clause conditions'
where there are clauses like this:
((q = 3) and (v 6))
from a table something like:
id g q v
1 1 1 3
2 1 2 2
3 1 3 4
4 1 5 8
5 1 6 1
1 2 1 3
2 2 2 2
3 2 3 6
4 2 5 8
5 2 6 1
...
which should work like this.
for group g = 1, q = 3, v 6 is valid, so return me all rows for g = 1
for group g = 2, q = 3, v 6 is bot valid, so don't return me all rows for g = 2
and so on...
so the result would be in this case
id g q v
1 1 1 3
2 1 2 2
3 1 3 4
4 1 5 8
5 1 6 1
as only group 1's rows match _all_ the clause conditions as a complete set.
the only way I can think to do this is to create a pivot table and put all the q values as columns and then I can run a normal query that tests q3>x and q5
so that leads me to my question
anyone know how to do a generic pivot in mysql (5.x) or know another way to solve this (maybe using stored procs)?
any help greatly appreciated, I'll carry on muddling through in the mean time hoping for a brainwave!