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

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

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
)
全部评论

相关推荐

我在朝九晚六双休的联想等你:如果我是你,身体素质好我会去参军,然后走士兵计划考研211只需要200多分。
点赞 评论 收藏
分享
牛客569470950号:也不知道是哪个群体45年前鬼哭狼嚎的为自己争取的被剥削的权利
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务