|
@@ -66,10 +66,10 @@ public class GoodsServiceImpl extends IBaseServiceImpl<GoodsEntity, Long> implem
|
|
|
StringBuffer sql = new StringBuffer();
|
|
|
// 使用了子查询
|
|
|
sql.append("select a.*, b.countLike as countLike, b.countVote as countVote from tb_goods a left join " +
|
|
|
- "(select g.id,sum(case v.type when 'like' then 1 else 0 end )countLike, " +
|
|
|
- "sum(case v.type when 'vote' then 1 else 0 end )countVote " +
|
|
|
- "from tb_goods g left join tb_goods_vote v on g.id=v.goods_id where g.is_delete=0 and v.is_delete=0 ) b " +
|
|
|
- "on a.id=b.id where a.is_delete=0");
|
|
|
+ "(SELECT id,goods_id, count(case when type='vote' then 1 end) countVote, " +
|
|
|
+ "count(case when type='like' then 1 end) countLike " +
|
|
|
+ "from tb_goods_vote WHERE is_delete=0 GROUP BY goods_id) b " +
|
|
|
+ "on a.id=b.goods_id where a.is_delete=0");
|
|
|
|
|
|
if (display != null){
|
|
|
sql.append(" and a.display=").append(display);
|