我在mysql中使用函数group_by,但在大数据116000记录中,当我运行这个sintax时,有超过1个相同的数据。我该怎么办?
SELECT fiedl1, field2, field3
FROM table
GROUP BY field2
ORDER BY 'field2' ASC
field1|field2|field3
1 |you |a
2 |you |b
3 |you |c
4 |you |d
5 ...etc
结果
field1|field2|field3
1 |you |a
2 |you |b
答案 0 :(得分:0)
最佳做法是在所有字段上使用group by,或者使用agregate函数,例如
SELECT fiedl1,field2,field3 从表 GROUP BY fiedl1,field2,field3 ORDER BY field2 ASC
OR
SELECT sum(fiedl1),field2,avg(field3) 从表 GROUP BY field2 ORDER BY field2 ASC