简体   繁体   English

MYSQL将数据从一个表转移到另一个表的过程

[英]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.

相关问题 将数据从一个 MySQL 表传输到另一个带参数的表 - Transfer data from one MySQL table to another w/ parameters MySQL-汇款:将数据从一个字段转移到同一表中的另一个字段 - Mysql - Money transfer: Transfer data from one field to another in the same table 将数据从一个数据库传输到另一个 MYSQL - Transfer data from one database to another MYSQL 插入时将数据从一个表转移到另一个表 - Transfer data from one table to another on insert MySQL-MySQL事件调度程序不会以设定的频率将数据从一个表传输到另一个表 - MySQL - MySQL event scheduler will not transfer data from one table to another on a set frequency Mysql-如何在每周的特定日期和时间将数据从一个表转移到另一个表? - Mysql - How can I transfer data from one table to another on a specific day and time in the week, every week? 使用带有字符串的额外列将数据从一个Mysql表传输到另一个 - Transfer data from one Mysql table to another with an extra column having a string Python脚本将数据从一台MySQL服务器传输到另一台MySQL服务器 - Python script to transfer data from one MySQL server to another one 如何使用游标创建存储过程以通过验证将数据从一个表移动到另一表(Mysql) - How to create stored procedure using cursor to move data from one table to another table with validation ( Mysql) MySQL从一个表到另一个PHP传输8000+行 - mySQL transfer 8000+ rows from one table to another PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM