mysql语句SELECT INSERT INTO提示

时间:2012-07-15 09:27:33

标签: mysql

我的声明正确缺少一个列,但它没有根据订单将表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

2 个答案:

答案 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