我有以下代码返回两个漂亮的表(在 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/