错误#1241-操作数在Mysql中应包含1列



我只是尝试以下查询:

SELECT *, 
      (
       SELECT count(*) 
       FROM users 
       where users.email=calls.email
      ) as ureg, 
      (
       SELECT sum(qty) 
       FROM product 
       where product.owner in 
          (SELECT * 
           from users 
           where users.email=calls.email)
      ) as pop 
FROM calls 
order by calls.data desc 
LIMIT 0,20

但我得到以下错误:

#1241 - Operand should contain 1 column(s)

我应该如何修复我的查询?

编辑:通过更改SELECT * from users where users.email=calls.emailSELECT id from users where users.email=calls.email

它之所以有效,是因为查询在用户中存在的一组id中搜索product.owner

where product.owner in (SELECT *

product.owner是一列,所以子查询应该返回一列(与product.owner相对应的列(。

尝试这个

 SELECT calls.*, count(users.*) as ureg, sum(twons.qty) as pop 
 FROM calls 
 INNER JOIN users ON users.email=calls.email
 INNER JOIN towns ON towns.id = users.town 
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^--you have to correct this to your table column names
  order by data desc 
  LIMIT 0,20
  • 您必须将此ON towns.id = users.town更正为您的表名

相关内容

  • 没有找到相关文章