mysql 关于某字段去重查询

 使用distinct 和 group by 对于查询多字段,而只对一个字段去重是查不到正确值得,因为distinct 后面跟多字段,mysql会对只有这些子对完全重复才能去重,而group by 查询的字段也只能在 group by 后面跟的字段,要根据某字段去重,我的做法是先对字段去重然后用group_concat 函数对不重复字段值拼接,然后通过存储过程过滤需要的数据即可
select group_concat(distinct field Separator '_') from xxx;

call process(select group_concat(distinct field Separator '_') from xxx)

猜你喜欢

转载自blog.csdn.net/adsadadaddadasda/article/details/82985202