gpt4 book ai didi

mysql - 使用特定列名将 MySQL 表值复制到重复表

转载 作者:行者123 更新时间:2023-11-29 07:22:34 26 4
gpt4 key购买 nike

我正在尝试将表的值复制到新表,以便我可以执行 ALTER 语句,而无需连续几天锁定表。

但是,我还想对表列结构进行一些更改。所以我不想使用 *

相反,我希望能够像普通插入语句一样指定列。 但由于某种原因它不喜欢这种语法?

INSERT INTO earnings_new 
(earning_account_id, earning_link_id, earning_ticket_id, earning_referral_id,
earning_referral_type, earning_ad_id, earning_verified, earning_paid, earning_amount, earning_country,
earning_country_id, earning_ip, earning_hour, earning_day, earning_month, earning_year, earning_created, earning_updated)
VALUES
(
SELECT
earning_account_id, earning_link_id, earning_ticket_id, earning_referral_id,
earning_referral_type, earning_ad_id, earning_verified, earning_paid, earning_amount, earning_country,
earning_country_id, earning_ip, earning_hour, earning_day, earning_month, earning_year, earning_created, earning_updated
FROM earnings
WHERE earning_month = 2 AND earning_day = 12 AND earning_hour = 13
GROUP BY earning_id
ORDER BY earning_created DESC
)

最佳答案

尝试省略 VALUES 关键字。

INSERT INTO earnings_new 
(earning_account_id, earning_link_id, earning_ticket_id, earning_referral_id,
earning_referral_type, earning_ad_id, earning_verified, earning_paid, earning_amount, earning_country,
earning_country_id, earning_ip, earning_hour, earning_day, earning_month, earning_year, earning_created, earning_updated)

(
SELECT
earning_account_id, earning_link_id, earning_ticket_id, earning_referral_id,
earning_referral_type, earning_ad_id, earning_verified, earning_paid, earning_amount, earning_country,
earning_country_id, earning_ip, earning_hour, earning_day, earning_month, earning_year, earning_created, earning_updated
FROM earnings
WHERE earning_month = 2 AND earning_day = 12 AND earning_hour = 13
GROUP BY earning_id
ORDER BY earning_created DESC
)

Reference

关于mysql - 使用特定列名将 MySQL 表值复制到重复表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35608102/

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