博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
p_vipshop_to_actual_day_shop_sale
阅读量:4214 次
发布时间:2019-05-26

本文共 1835 字,大约阅读时间需要 6 分钟。

delimiter $$ 
create procedure p_vipshop_to_actual_day_shop_sale
(
in p_shop_id int,
in p_sale_date date,
out p_update_insert varchar(50)
)
#毛利率
begin 
SELECT
@margin:=sum(profit) / sum(sale_amt) 
FROM
(
SELECT DISTINCT
tmp1.product_id,
tmp1.sale_amt,
tmp1.sale_num * t2.cost_price AS total_cost,
t2.cost_price AS cost,
tmp1.sale_amt - tmp1.sale_num * t2.cost_price AS profit
FROM
(
SELECT
t1.product_id,
sum(t1.total_sale_amount) AS sale_amt,
sum(t1.total_sale_number) AS sale_num
FROM
order_vipshop_daily_detail_info t1
WHERE
(
shop_id = p_shop_id
AND sale_date = p_sale_date
)
GROUP BY
t1.product_id
) tmp1
JOIN l3_product_inherent_property_code t2 ON tmp1.product_id = t2.product_id
) tmp;
#销售额,销量,件单价
SELECT
@amt:= sum(total_sale_amount),
@num:= sum(total_sale_number) ,
@price:= sum(total_sale_amount) / sum(total_sale_number)
FROM
order_vipshop_daily_detail_info
WHERE
(
shop_id = p_shop_id
AND sale_date = p_sale_date
);
# 写入数据更新字段 rate_of_margin,unit_price,place_num,place_amount
if not exists(
select 1 from actual_day_shop_sale
where shop_id=p_shop_id and the_date=p_sale_date
)
then 
 
insert actual_day_shop_sale(the_date,shop_brand_id,`year`,`month`,`day`,shop_id,shop_name,
brand_id,actual_sale,description,rate_of_margin,unit_price,place_num,place_amount)
values(
p_sale_date
,(SELECT shop_brand_id from base_shop_brand where shop_id=p_shop_id)
,year(p_sale_date)
,month(p_sale_date)
,day(p_sale_date)
,p_shop_id
,(select shop_name from base_shop where shop_id=p_shop_id)
,(SELECT brand_id from base_shop_brand where shop_id=p_shop_id)
,@amt
,'ETL Input'
,@margin
,@price
,@num
,@amt
);
set p_update_insert='insert';
 
else
 
update actual_day_shop_sale 
set rate_of_margin=@margin,place_amount=@amt,place_num=@num,unit_price=@price
where shop_id=p_shop_id and the_date=p_sale_date;
set p_update_insert='update';
 
end if ;
end ;
$$

转载地址:http://llfmi.baihongyu.com/

你可能感兴趣的文章
mac 下获取root权限
查看>>
intellij svn切换地址
查看>>
HATEOAS 返回结果content被隐藏
查看>>
intellij cvs切换地址
查看>>
centos7通过yum安装JDK1.8
查看>>
CentOS 安装rz和sz命令 lrzsz
查看>>
spirng-data-ldap 给ad设置和修改用户的密码需要 ldaps访问
查看>>
awk 用法
查看>>
shell 自动填入提示参数
查看>>
三建kafka linux 安装kafka
查看>>
maven打包不同jdk版本的包
查看>>
如何让redirect隐藏rul参数
查看>>
ad的pwdLastSet,微软时间戳转java的date
查看>>
java操作ad,创建用户设置 “用户下次登录时须更改密码”
查看>>
java 计算之前的一个日期
查看>>
springdata ldap 添加用户到用户组
查看>>
IDEA 由于DAO 引起的 Could not autowire. No beans of 'xxxx' type found
查看>>
Sequel pro 意外退出 每次关闭一个会话 必报错
查看>>
自学模具设计的分析
查看>>
CNC模具编程的工作流程
查看>>