select g.id,
(select count(*), sum(sales)
FROM transactions t1
where t1.customernumber between g.from_customernumber and g.to_customernumber)
from customer_groups g
mysql不允许从子查询中获取多个列,在中使用 SELECT 条款。您可以将子查询改为 FROM part作为派生表,并连接到 customer_groups 相应的表格。 请改为使用以下命令:
SELECT g.id,
dt.count,
dt.total_sales
FROM customer_groups AS g
JOIN
(
SELECT customernumber,
COUNT(*) as count,
SUM(sales) as total_sales
FROM transactions AS t1
GROUP BY customernumber
) AS dt
ON dt.customernumber BETWEEN g.from_customernumber AND
g.to_customernumber
1条答案
按热度按时间mrphzbgm1#
mysql不允许从子查询中获取多个列,在中使用
SELECT
条款。您可以将子查询改为FROM
part作为派生表,并连接到customer_groups
相应的表格。请改为使用以下命令: