[英]MYSQL Procedure to transfer data from one table to another
I'm new in mysql and plsql as well. 我也是mysql和plsql的新手。 I was trying to write one procedure to transfer data from one table to another but couldnt reach to end.
我试图编写一个过程将数据从一个表转移到另一个表,但是无法到达终点。
I have one table Mall_Sales (Consist of three different malls like Delhi_Mall, Mumbai_Mall, Chennai_Mall and these malls falls in column Mall with their period of transaction in column name Period ) 我有一张桌子Mall_Sales(由Delhi_Mall,Mumbai_Mall,Chennai_Mall之类的三个不同的购物中心组成,这些购物中心位于“ Mall”列中,其交易期限在“ Period”列中)
Mall_Sales Mall_Sales
Mall Period
Delhi_Mall 2015-09-01
Delhi_Mall 2015-09-02
Delhi_Mall 2015-09-03
Mumbai_Mall 2015-09-01
Mumbai_Mall 2015-09-02
Chennai_Mall 2015-09-01
Chennai_Mall 2015-09-02
And 和
Latest_Period_Mall
Mall Period
Delhi_Mall 2015-09-03
Mumbai_Mall 2015-09-02
Chennai_Mall 2015-09-02
I'm trying to write a procedure whenever period of mall updates in Mall_Sales, Store MAX period of all malls in Latest_Period_Mall table. 我试图在Mall_Sales中更新商场期间,将所有商场的MAX期间存储在Latest_Period_Mall表中时编写一个过程。
And whenever new MAX date comes from Mall_Sales table should replace the existing records in Latest_Period_Mall table. 并且只要Mall_Sales表中有新的MAX日期,就应该替换Latest_Period_Mall表中的现有记录。
I have tried this 我已经试过了
Create or replace Procedure Update_Data
AS
INSERT into Latest_Period_Mall table(Mall, Period)
Select Mall, MAX(Period) Period
from Mall_Sales
group by Mall
Go
Please correct me with your inputs and the every time updation part in Latest_Period_Mall table rather than adding records. 请用您的输入以及Latest_Period_Mall表中的每次更新部分来纠正我,而不要添加记录。
Best 最好
A view essentially saves the query: 视图本质上保存了查询:
create view Latest_Period_Mall as
Select Mall, MAX(Period) Period
from Mall_Sales
group by Mall
So that you can simply query the view like a regular table. 这样您就可以像常规表一样简单地查询视图。
select * from latest_period_mall
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.