【问题标题】:using mysql query to fill the rows of an empty table使用 mysql 查询填充空表的行
【发布时间】:2015-08-04 15:50:58
【问题描述】:

我需要分析 mysql 中的一些数据,并且我正在尝试创建一个主要基于现有表的新表。到目前为止,我已经创建了包含几十个左右必要列的表。它们与查询中的列(我可以轻松更改)不同,但新表中的每一列都包含在查询中。查询和新表中的列也没有以完全相同的顺序找到,但如果需要,我也可以更改它。我应该如何用查询中的所有必要数据填充我的表——100,00 行?这是查询的格式:

select t2.name as agent,t1.* from
(select s.year, s.wk, t.* from sales s 
join transaction t
on s.id = t.id) t1,

(select s.year, s.wk, t.* from sales s 
join transaction t
on s.id = t.id) t2 

where t1.id=t2.id
and 
t1.name<>t2.name

【问题讨论】:

  • 你考虑过create table asinsert into吗?
  • 我在 mysql 中创建的第一个表就是问题所在。我看到了向表中添加数据的两个选项,但找不到我正在尝试做的示例

标签: mysql sql


【解决方案1】:
create table myNewTable as
(select t2.name as agent,t1.* from
(select s.year, s.wk, t.* from sales s 
join transaction t
on s.id = t.id) t1,

(select s.year, s.wk, t.* from sales s 
join transaction t
on s.id = t.id) t2 

where t1.id=t2.id
and 
t1.name<>t2.name)

我建议你看看你的查询是如何工作的,因为你的 t1 和 t2 查询是相同的,所以很可能总是匹配的(除非我只是遗漏了一些东西)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-06
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    相关资源
    最近更新 更多