SQL查询语句&&1、查询商品id等于8且有效的评论内容。 2、查询每个用户评论的商品数量。 3、查询最新发布的5条有效商品评论信息。 4、查询评论过两种以上不同商品的用户id及对应的商品id。

SQL根据商品表(sh_goods)与商品评论表(sh_goods_comment )

1、查询商品id等于8且有效的评论内容。
2、查询每个用户评论的商品数量。
3、查询最新发布的5条有效商品评论信息。
4、查询评论过两种以上不同商品的用户id及对应的商品id。
5、查询没有任何评论信息的商品id和name。
6、查询商品评分为5星的商品评论信息。


select * from shop.sh_goods_comment;
select goods_id,content,is_show 
from shop.sh_goods_comment where goods_id=8 and is_show=1;

-- 根据商品表(sh goods)与商品评论表(sh goods comment)查询商品id等于8且有效的评论内容
select goods_id,content,is_show 
from shop.sh_goods_comment where goods_id=8 and is_show=1;

-- 查询每个用户评论的商品数量 
SELECT user_id, COUNT(DISTINCT goods_id) as num_comments
FROM shop.sh_goods_comment
GROUP BY user_id;

-- 查询最新发布的5条有效商品评论信息
SELECT id, goods_id, content, create_time
FROM shop.sh_goods_comment
WHERE is_show = 1
ORDER BY create_time DESC
LIMIT 5;

-- 5、查询评论过两种以上不同商品的用户id和对应商品id
select user_id,goods_id,content 
from sh_goods_comment 
where user_id in (select user_id from sh_goods_comment group by user_id);

-- 6、查询没有任何评论信息的商品id和name
select id ,name from sh_goods 
where id not in (select distinct(goods_id) from sh_goods_comment);

-- 7、查询商品评分为5星的商品评论信息
select content from sh_goods_comment 
where goods_id in (select id from sh_goods where score=5);






  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值