我有
| id | name | v1 | v2 | rate_id |
-------------------------------------
| 1 jack 202 2 18
| 2 jack 202 3 23
| 3 gad 204 2 34
| 4 vad
| 5 mad
| 6 pad

avarage =(最高费率+最低费率)/ 2 其中name = jack AND v1 = 202 AND v2 = 2 也适用于(name,v1,v2)
的每个唯一行和avarage的结果应该在其他选择查询中:
SELECT
m.rate = avarage
FROM messages m
INNER JOIN rates r
ON r.id = m.rate_id

答案 0 :(得分:1)
使用Group By
和Aggregate
select name,v1,v2, (max(rate) + min(rate)) / 2 As `Average`
From messages m
INNER JOIN rates r
ON r.id = m.rate_id
Group by name,v1,v2