我的声明正确缺少一个列,但它没有根据订单将表trending_topics
中的#标签符号插入rss
表。
任何调整都可以帮助我完成我的陈述。
INSERT INTO rss (id,hashtag,total)
SELECT
hashtag,
SUM(count) AS total
FROM `trending_topics`
WHERE lang=0
AND hashtag != ''
AND date >= date_sub(left(now(), 10), interval 1 day)
GROUP BY hashtag order by total desc;;
我在表格中的插入(rss
)如下所示:
id hashtag total
1 null 55
2 null 22
答案 0 :(得分:2)
如果数据类型和您的示例sql等正确(并且select返回了一个hashtag),则以下内容应该有效(删除插入到语句中的id )
INSERT INTO rss (hashtag,total)
SELECT
hashtag,
SUM(count) AS total
FROM `trending_topics`
WHERE lang=0
AND hashtag != ''
AND date >= date_sub(left(now(), 10), interval 1 day)
GROUP BY hashtag order by total desc;
答案 1 :(得分:1)
插入的字段数应与INSERT INTO table_name (field list)
INSERT INTO rss (hashtag,total)
SELECT
hashtag,
SUM(count) AS total