gpt4 book ai didi

MySQL:从 SELECT 语句到 INSERT 语句

转载 作者:行者123 更新时间:2023-11-29 04:45:26 33 4
gpt4 key购买 nike

我有以下代码返回两个漂亮的表(在 PhpMyAdmin 中使用 SQL 函数时)。但是,我无法将它们插入到我的 TABLE B 中。

我怎样才能将它插入表 B 而不仅仅是显示它?

SELECT DateTimeCode, Rat,
MAX(IntendedStimulusDuration_ms) AS StimulusDuration,
SUM(Correct + Incorrect + Omission + PrematureNosepokes) AS total_trials,
SUM(Correct) AS correct,
SUM(Incorrect) AS incorrect,
SUM(Omission) AS omission,
SUM(PrematureNosepokes) AS premature,
SUM(PerseverativePanelPushes) AS P_PanelPushes,
SUM(PerseverativeNosepokes) AS P_nosepokes,
SUM(PerseverativeNosepokesSameHole) AS P_NPsame,
SUM(PerseverativeNOsepokesOtherHoles) AS P_NPother
FROM `FiveChoice_TrialData`
GROUP BY Rat,DateTimeCode;

--If correct = 1
SELECT DateTimeCode, Rat,
AVG(ResponseLatency_ms) AS ResponseLatency,
AVG(CollectionLatency_ms) AS CollectionLatency
FROM `FiveChoice_TrialData`
WHERE Correct = 1
GROUP BY Rat,DateTimeCode;

基本上我试过:

INSERT INTO TABLE_B (--all my col names, just like the alias stated above)
VALUE (--My two select statement as written above, separated by a coma)

最佳答案

从查询中插入时,您不需要 value 语句。试试这个:

insert into table_b(<list of columns here>)
SELECT DateTimeCode, Rat,
MAX(IntendedStimulusDuration_ms) AS StimulusDuration,
SUM(Correct + Incorrect + Omission + PrematureNosepokes) AS total_trials,
SUM(Correct) AS correct,
SUM(Incorrect) AS incorrect,
SUM(Omission) AS omission,
SUM(PrematureNosepokes) AS premature,
SUM(PerseverativePanelPushes) AS P_PanelPushes,
SUM(PerseverativeNosepokes) AS P_nosepokes,
SUM(PerseverativeNosepokesSameHole) AS P_NPsame,
SUM(PerseverativeNOsepokesOtherHoles) AS P_NPother
FROM `FiveChoice_TrialData`
GROUP BY Rat,DateTimeCode;

第二个查询类似。

关于MySQL:从 SELECT 语句到 INSERT 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19781151/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com