我想从第一列获取计数并将它们放在第二列的匹配行中。
选择来源,计算(*)来自客户,其中leadource不为null和leadource!="" group by leadource;
select leadsource,count(*) from customers where leadsource is not null and leadsource !="" group by leadsource;
+---------------------+----------+
| leadsource | count(*) |
+---------------------+----------+
| Show 2014 | 2 |
| Show 2013 | 4 |
| By Me | 1 |
+---------------------+----------+
select source,leads from lead_report;
+---------------------+-------+
| source | leads |
+---------------------+-------+
| Show 2014 | 0 |
| Show 2013 | 0 |
| By Me | 0 |
+---------------------+-------+
update lead_report leads inner join
(select leadsource,count(*) from customers where leadsource is not null and leadsource !="" group by leadsource)
customers using (leadsource) set lead_report.leads = customers.leadsource;
ERROR 1054 (42S22): Unknown column 'leadsource' in 'from clause'
答案 0 :(得分:0)
update lead_report lr join
(select leadsource, count(*) cnt from customers
where leadsource is not null and leadsource !="" group by leadsource) cust
ON lr.source=cust.leadsource
SET lr.leads=cust.cnt;