[英]Taking data from one table and inserting it into another MySQL
I currently have a code of: 我目前有一个代码:
UPDATE graph AS s
JOIN (SELECT Player, (Score) AS newscore
FROM scores
GROUP BY Player) AS d
JOIN (SELECT Player, (Player) AS newplayer
FROM scores
GROUP BY Player) AS e
JOIN (SELECT curdate()) AS q
insert into s ( s.Score, s.Player, s.Date) values ( newplayer, newscore, q);
What I am trying to do is take data from one table and put it into the other. 我想做的是从一个表中获取数据,然后将其放入另一个表中。
The first table "graph" is where I want new data put into, it has three fields: 我要在其中插入新数据的第一个表“图形”,它具有三个字段:
Date Score Player 日期分数播放器
The second table "scores" is where I want to take the data from, it has many fields but only two are of importance for this: 第二个表“分数”是我要从中获取数据的地方,它有很多字段,但是只有两个很重要:
Player Score 球员得分
I want to take the data of the current day (Player and Score) and create a new line inside of "graph" using Player Score and CURDATE. 我想获取当天的数据(玩家和得分),并使用玩家得分和CURDATE在“图”中创建新行。
anyone know what I can do to make my code work? 有人知道我可以做些什么来使我的代码工作吗? or maybe have a better idea for my code?
还是对我的代码有更好的主意?
Thank you. 谢谢。
-edit- -编辑-
Data in scores table 分数表中的数据
dem0n123 1220 dem0n123 1220
Mordrah 1236 莫德拉1236
extcy 1245 外部1245
What I want the new data in the graph table to look like 我希望图表表中的新数据看起来像什么
dem0n123 1220 2013-12-03 dem0n123 1220 2013-12-03
Mordrah 1236 2013-12-03 莫德拉1236 2013-12-03
extcy 1245 2013-12-03 extcy 1245 2013-12-03
You could use something like this: 您可以使用如下形式:
CREATE TABLE scores
(`name` varchar(25), `value` int)
;
INSERT INTO scores
(`name`, `value`)
VALUES
('dem0n123', 1220),
('Mordrah', 1236),
('extcy', 1245)
;
CREATE TABLE graph
(`name` varchar(25),
`value` int,
`mydate` DateTime);
insert into graph (name, value, mydate)
select name,value, CURDATE() from scores
select name,value,mydate from graph
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.