I have a problem when I try to calculate the sum of the values โโfor each identifier. I decided to do this using subqueries (typically I would use a join, but I also keep a counter for each subquery for clipping purposes - see this question for more information). For this question, suppose I have the following MySQL query:
SELECT
t1.experiement_id,
(SELECT sum(x.size)
FROM (SELECT size, ( @rownum := @rownum + 1 ) AS `rownum`
FROM data AS t0
JOIN ( select @rownum := 0 )
WHERE t0.experiment_id = t1.experiment_id
ORDER BY size) AS x
WHERE x.rownum <= t2.clip_index ) AS `sum`
FROM data AS t1
JOIN data_clip AS t2 USING (experiment_id)
GROUP BY t1.experiment_id
7, , experiement_id. , t1.experiement_id . , 1 . , , , t2.clip_index . # 7, ( ). , ? .