SELECT
m1.recdate, m1.rectime, m1.equip, m1.reason,
m2.recdate, m2.rectime, m2.downtime
FROM main AS m1
LEFT JOIN main AS m2
ON SELECT MIN(m2.num) m2.num > m1.num AND m2.equip = m1.equip AND m2.state = 'ПУСК' AND m1.state = 'СТОП' GROUP BY m1.num
SELECT m1.recdate,m1.rectime,m1.equip,m1.reason,m2.recdate,m2.rectime,m2.downtime FROM main AS m1
LEFT JOIN main AS m2 ON m2.num=MIN(m2.num) (m2.num>m1.num) AND (m2.equip=m1.equip) AND (m2.state='ПУСК') GROUP BY m2.num
WHERE (m1.state='СТОП')
, но оно, конечно, не работает. Что нужно поправить? SELECT m1.recdate,m1.rectime,m1.equip,m1.reason,m2.recdate,m2.rectime FROM main AS m1
LEFT JOIN main AS m2 ON m2.num=(SELECT m3.num FROM main AS m3 WHERE (m3.num>m1.num) AND (m3.equip=m1.equip) AND (m3.state='ПУСК') ORDER BY m3.num LIMIT 1)
WHERE (m1.state='СТОП')