数据库
首页 > 数据库> > Mysql分页查询出现重复数据

Mysql分页查询出现重复数据

作者:互联网

1、执行sql语句,根据商品销量来进行分页查询

SELECT
  goods_spu.*
FROM
  goods_spu goods_spu
WHERE goods_spu.`shop_id` = '1450999734971478018'
  AND goods_spu.`shelf` = 1
  AND goods_spu.tenant_id = '1'
ORDER BY goods_spu.sale_num DESC
LIMIT 0,10

当所有商品销量都为0或者都一样的情况下就会出现不同分页参数情况下会出现重复的商品

2、解决办法

增加排序条件

可改成:

SELECT
  goods_spu.*
FROM
  goods_spu goods_spu
WHERE goods_spu.`shop_id` = '1450999734971478018'
  AND goods_spu.`shelf` = 1
  AND goods_spu.tenant_id = '1'
ORDER BY goods_spu.sale_num DESC,goods_spu.id
LIMIT 0,10

标签:shop,goods,分页,spu,查询,num,Mysql,id
来源: https://blog.csdn.net/zhuxiang997/article/details/123066592