In mysql, user information is intercepted cyclically and inserted into the corresponding fields of the target table. mysql user information

Source: Internet
Author: User
Tags add time

In mysql, user information is intercepted cyclically and inserted into the corresponding fields of the target table. mysql user information

Operating Environment: Table game_list, field: uid, score1, score2, seat_id, last_update;
The input parameter is I _player_detail. The input value is the id, previous score, post score, and seat number of multiple users. Data of each user is separated by semicolons;
Objective: To insert the attributes of each user to the fields of the target table, and last_update indicates the data update date;
The input parameter I _player_detail stores the information of multiple users. A group of data of each user is separated by semicolons. each user has multiple information, such
"User ID, score, desk, seat;
User ID, score, desk, seat ;......"

-- Use stored procedure delimiter $ use 'Log _ pdk' $ drop procedure if exists 'game _ C' $ create procedure 'game _ C' (in I _player_detail varchar (500)) SQL SECURITY INVOKERBEGINDROP TABLE IF EXISTS 'temp _ list'; -- create a temporary TABLE, insert the intercepted data to the temporary table create temporary table 'temp _ List' ('uid' INT (10) unsigned not null, 'score1' INT (10) unsigned not null, 'score2' INT (10) unsigned not null, 'seat _ id' TINYINT (3) unsigned not null); -- declare str varchar (500 ); -- used to splice the SQL dynamic statement declare m_detail varchar (500); declare m_num tinyint; -- when the input user information string contains a semicolon ';', extract set m_num = position ('; 'In str) -- returns 0 while m_num> = 1 dobeginset @ str = 'insert into temp_list values ('+ substring (m_detail, 1, m_num-1) +' if there is no semicolon ') '-- intercept the information of the first user (the character before the first semicolon) and insert it to the temporary table prepare statement1 from @ str; execute statement1; deallocate prepare statement1; set m_detail = substring (m_detail, m_num + 1); -- defines the string set m_num = position (';' in str); end while; -- Extract all fields from the temporary table, add time fields, and insert them to the game_listINSERT INTO 'game _ List' ('uid', 'score1', 'score2 ', 'seat _ id', 'last _ Update') SELECT 'uid', 'score1', 'score2', 'seat _ id', current_date () FROM 'temp _ list'; end $ delimiter;


Mysql queries the fields of one table and inserts the fields of another table.

Insert into t2 (id, old, up, new, qq, time) select id, gold, 1, gold + 1, qq, sysdate () from t1 where qq in (qq1, qq2, qq3 );

How does mysql query all the information of two tables at the same time? One Table field corresponds to the primary key field of the other table

SELECT *
FROM 'order'
Inner join 'userinfo' ON 'userinfo'. 'userid' = 'order'. 'uid'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.