0

我有一个具有这种结构的表:

CREATE TABLE `jos_cpnllist` (
    `MSTMLSNO` int(7),
    `CLTIME` TIMESTAMP NULL,
    PRIMARY KEY (`MSTMLSNO`))
    ENGINE=MyISAM 
    SELECT * FROM jos_mls AS mls
        INNER JOIN jos_activeagents AS active ON mls.MSTLISTBRD = active.AGENTUID
        INNER JOIN jos_agents AS agents ON active.AGENTUID = agents.AGTBRDIDMM;

然后我想定期更新此表中的数据:

INSERT INTO jos_cpnllist
    SELECT * FROM jos_mls AS mls
        INNER JOIN jos_activeagents AS active ON mls.MSTLISTBRD = active.AGENTUID
        INNER JOIN jos_agents AS agents ON active.AGENTUID = agents.AGTBRDIDMM;

当我进行更新时,添加的时间戳列给我带来了麻烦:

ERROR 1136 (21S01): Column count doesn't match value count at row 1

有没有办法解决这个问题而无需专门列出SELECT? 告诉它忽略CLTIME时间戳列?

注意:这就像 75 列数据,所以我想避免列出所有这些。该MSTMLSNO列已存在于jos_mls表中,因此不会引发错误。CLTIME是大 INNER JOIN 语句中唯一不存在的列。

4

1 回答 1

3

使用插入时,始终明确指定列:

INSERT INTO jos_cpnllist(MSTMLSNO, CLTIME)
    SELECT <columnX> as MSTMLSNO, <columnY> as CLTIME
    FROM jos_mls AS mls
        INNER JOIN jos_activeagents AS active ON mls.MSTLISTBRD = active.AGENTUID
        INNER JOIN jos_agents AS agents ON active.AGENTUID = agents.AGTBRDIDMM;

列出 75 列并不难。您可以从 Excel 中获取列表INFORMATION_SCHEMA.columns并对其进行格式化。

于 2013-05-29T16:35:05.510 回答