我有一个查询,如下所示:
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...]
关于mysql - SQL 查询从选择查询的输出插入到特定列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32855337/