mysql++临时表生命周期_mysql - 临时表暂存数据
发布日期:2021-06-24 13:48:44 浏览次数:2 分类:技术文章

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

1. 使用临时表暂存数据,然后拼接得到的所有结果(postgresql)

drop table IF EXISTS temp_stock_beginning;

drop table IF EXISTS temp_stock_move_in;

drop table IF EXISTS temp_stock_move_out;

create temp table temp_stock_beginning(product_id int, location_id int,qty int,res_company_id int);

create temp table temp_stock_move_in(product_id int, location_id int,qty int,res_company_id int);

create temp table temp_stock_move_out(product_id int, location_id int,qty int,res_company_id int);

insert into temp_stock_beginning(product_id,location_id,qty,res_company_id int)

select product_id,stock_location_id as location_id,qty,res_company_id

from company_stock_remain

where data_date='{}';

insert into temp_stock_move_in(product_id,location_id,qty,res_company_id)

select product_id,b.origin_id as location_id,-1*qty,res_company_id

from company_stock_move_detail a

inner join stock_location b on a.from_stock_location_id=b.id

where b.usage='internal' and a.data_date='{}';

insert into temp_stock_move_out(product_id,location_id,qty,res_company_id)

select product_id,b.origin_id as location_id,qty ,res_company_id

from company_stock_move_detail a

inner join stock_location b on a.to_stock_location_id=b.id

where b.usage='internal' and a.data_date='{}';

insert into company_stock_remain(product_id,stock_location_id,qty,data_date,res_company_id)

select product_id,location_id,sum(qty),'{}',res_company_id from

(select product_id,location_id,qty,res_company_id from temp_stock_beginning

union all

select product_id,location_id,qty,res_company_id from temp_stock_move_in

union all

select product_id,location_id,qty,res_company_id from temp_stock_move_out

) as a

where qty != 0

group by product_id,location_id

标签:product,临时,company,qty,location,mysql,暂存,id,stock

来源: https://www.cnblogs.com/JackShi/p/14078357.html

转载地址:https://blog.csdn.net/weixin_33245447/article/details/114817540 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:pm模式 raid_如何进入ThinkSystem系列服务器SAS RAID阵列配置界面
下一篇:java学生管理系统编号_java学生信息管理系统(附源码)

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月15日 05时01分39秒