1

I have the following code that returns me two nice tables (When using the SQL function in PhpMyAdmin). However, I am unable to insert them into my TABLE B.

How can I insert this in TABLE B rather than only showing it?

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;

Basically I tried:

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)
4

1 回答 1

4

从查询插入时不需要该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;

和第二个查询类似的东西。

于 2013-11-05T02:54:35.707 回答