mysql - SQL 查询从选择查询的输出插入到特定列

标签 mysql

我有一个查询,如下所示:

select department as departmentname,count(distinct(uid)) as userscnt 
from outlier_report where department is not null group by department ;

我想将其插入到已经填充的 outlier_output 表中,该表有大约 20 个字段,包括部门名称和用户计数(该字段为空)。 我想将 select 输出中的 userscnt 字段放入 outlier_output 表中,其中 Department=outlier_report.department_name

我假设它会是这样的:

Insert into outlier_output(user_count Select department, count(distinct(uid) as userscnt from outlier_report where the department=outlier_report.departmentment_name)

确切的查询是怎样的? 提前致谢

最佳答案

标准插入选择格式是:

INSERT INTO `tableA` ([field_list])
SELECT [results corresponding to items in the field list in the same order as the field list]
[etc...]

http://dev.mysql.com/doc/refman/5.6/en/insert.html

关于mysql - SQL 查询从选择查询的输出插入到特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855337/

相关文章:

Mysql 日期 太阳日期

mysql - 为列的每个不同值选择一行,MySQL

mysql - 带 CaseBuilder 的 EnumPath(QueryDSL 3.6.2)

php - 在 PHP 中链接数据库的内部服务器错误

mysql - 从具有特定值的表中获取值列表

mysql - golang 现在用松鼠更新设置时间

mysql - 无法连接到 MySQL 的 Spring Boot 应用程序故障排除

mysql - 我是否需要在查询中包含分区名称才能获得分区的实际好处?

mysql - 如何从多个表中选择一个(或零个)条目,并将这些值添加在一起以匹配特定值?

php - 在 URL App Inventor 中使用大于 ( >= )