当 col3 和 col4 的值相同时,取 col2 的值max 的那一个
SELECT col1, col2, col3, col4,
@row_number := IF(@prev_value=CONCAT(col3, '-', col4), @row_number+1, 1) AS rn,
@prev_value := CONCAT(col3, '-', col4)
FROM table1
JOIN (SELECT @row_number := 0, @prev_value := '') AS vars
WHERE condition;
@row_number 获取行号
select t1.col1 from ( SELECT col1, col2, col3, col4,
@row_number := IF(@prev_value=CONCAT(col3, '-', col4), @row_number+1, 1) AS rn,
@prev_value := CONCAT(col3, '-', col4)
FROM table1
JOIN (SELECT @row_number := 0, @prev_value := '') AS vars
WHERE condition ) t1 where t1.rn = 1