I need the result for every combination of (from_id, to_id) which has the minimun value and the loop matching a criteria.
因此,我基本上需要具有微型价值的通道。 e. 例如,从A到B,需要微型价值和补贴。
The table has the following fields:
value from_id to_id loop_id
-------------------------------------
2.3 A B 2
0.1 A C 2
2.1 A B 4
5.4 A C 4
结果是:
value from_id to_id loop_id
-------------------------------------
2.1 A B 4
0.1 A C 2
I have tried with the following:
SELECT t.value, t.from_id, t.to_id,t.loop_id
FROM myresults t
INNER JOIN (
SELECT min(m.value), m.from_id, m.to_id, m.loop_id
FROM myresults m where m.loop_id % 2 = 0
GROUP BY m.from_id, m.to_id, m.loop_id
) x
ON (x.from_id = t.from_id and x.to_id=t.to_id and x.loop_id=t.loop_id )
AND x.from_id = t.from_id and x.to_id=t.to_id and x.loop_id=t.loop_id
But it is returning all the loops. Thanks in advance!