题解 | 更新用户积分信息?

# 筛选出订单表中积分消费金额大于100的订单
with t1 as(
        select user_id
            ,sum(order_price) as all_score
            from order_tb
        where order_price >100
        group by user_id),

# 筛选出会员表中有消费订单的会员
t2 as(
select user_id
      ,point
    from uservip_tb
where user_id in (select user_id
            from order_tb
        where order_price >100
        group by user_id))

# 将两个表连在一起,然后积分相加得出结果
select user_id
      ,all_score + point as point
    from(
        select t1.user_id as user_id
            ,all_score
            ,point
            from t1 join t2
                on t1.user_id=t2.user_id) as t3
order by point desc


























全部评论

相关推荐

不愿透露姓名的神秘牛友
2024-12-18 10:40
1 1 1 大专
offer来鸟:全网HR没见过像他家一样高傲不回消息的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务