我只是尝试以下查询:
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.email
到SELECT 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
更正为您的表名