7

我只是尝试以下查询:

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它之所以有效,是因为查询在用户中存在的一堆 s 中搜索 product.owner

4

2 回答 2

18
where product.owner in (SELECT *

product.owner是一列,因此子查询应返回一列(对应于product.owner)。

于 2013-06-05T17:09:41.390 回答
1

尝试这个

 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为您的表名
于 2013-06-05T17:21:40.163 回答