题解 | #某店铺的各商品毛利率及店铺整体毛利率#

某店铺的各商品毛利率及店铺整体毛利率

http://www.nowcoder.com/practice/65de67f666414c0e8f9a34c08d4a8ba6

select
  "店铺汇总" product_id,
  concat(
    round(
      100 * round(
        1 - (sum(tpi.in_price * tod.cnt) / sum(tod.price * tod.cnt)),
        3
      ),
      1
    ),
    "%"
  ) profit_rate
from
  tb_product_info tpi
  inner join tb_order_detail tod on tpi.product_id = tod.product_id
  inner join tb_order_overall too on too.order_id = tod.order_id
where
  date_format(too.event_time, "%Y-%m") >= "2021-10"
  and tpi.shop_id = 901
group by
  tpi.shop_id
union all
(
  select
    tpi.product_id,
    concat(
      round(
        100 * round(
          1 - (
            sum(tpi.in_price) * sum(tod.cnt) / (sum(tod.price) * sum(tod.cnt))
          ),
          3
        ),
        1
      ),
      "%"
    ) profit_rate
  from
    tb_product_info tpi
    inner join tb_order_detail tod on tpi.product_id = tod.product_id
    inner join tb_order_overall too on too.order_id = tod.order_id
  where
    date_format(too.event_time, "%Y-%m") >= "2021-10"
    and tpi.shop_id = 901
  group by
    tpi.product_id
  having
    round(1 - (avg(tpi.in_price) / avg(tod.price)), 3) > 0.249
  order by
    product_id
)
全部评论

相关推荐

10-13 17:47
门头沟学院 Java
wulala.god:图一那个善我面过,老板网上找的题库面的
点赞 评论 收藏
分享
伟大的烤冷面被普调:暨大✌🏻就是强
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:52
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务