【mybatis plus】distinct去重复查询的使用

查询的结果有时会有重复值,需要去除重复值,在sql查询中使用distinct关键字很方便的达到效果。例如:

SELECT distinct ckbm,qy,hwbm 
FROM base_kf_hwxx 
WHERE ckbm = '101' AND qy = 'A' AND isnull(hwxx_status,0)=0 AND qybs = 0

对应的实现代码:

 emptyhw_wrapper.select("distinct ckbm,qy,hwbm")
 		        .eq("ckbm", ckbm)
    		    .eq("qy", qy)
    		    .apply("isnull(hwxx_status,0)=0")
    		    .eq("qybs", 0);

指定查询的字段时加上distinct关键字: select(“distinct ckbm,qy,hwbm”) 。

发布了23 篇原创文章 · 获赞 2 · 访问量 4238

猜你喜欢

转载自blog.csdn.net/weixin_45616483/article/details/103786564