Mysql ERROR 1241 (21000): 操作数应包含 1 列 [英] Mysql ERROR 1241 (21000): Operand should contain 1 column(s)
本文介绍了Mysql ERROR 1241 (21000): 操作数应包含 1 列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有具有编号范围(从 Customernumber 到 Customernumber)的客户组.
I have Customer Groups with Number-Ranges (from Customernumber, to Customernumber).
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
选择此项时出现此错误
ERROR 1241 (21000): Operand should contain 1 column(s)
我该怎么做才能解决这个问题?我已经阅读了一些关于此的主题,但我没有找到解决方案.
What can i do to fix this? I've read some threads about this but I didn't find a solution for this.
最好的问候!
推荐答案
MySQL 期望您的子查询中有一个列,即括号中的 SELECT 只能对单个列进行 SELECT.
MySQL is expecting a single column from your subquery, i.e. the SELECT in the brackets can only SELECT for a single column.
在您的示例中,您可以使用两个子查询,一个返回计数,另一个返回总和,但您也可以将查询重写为:
In your example, you could use two subqueries, one that returns the count and one other that returns the sum, but you could also rewrite your query as this:
SELECT g.id, COUNT(t1.customernumber), SUM(sales)
FROM
customer_groups g LEFT JOIN transactions t1
ON t1.customernumber between g.from_customernumber and g.to_customernumber
这篇关于Mysql ERROR 1241 (21000): 操作数应包含 1 列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文