我无法理解错误代码。我从客户表中获取客户名称,然后我想从分支表中获取出价的cid,然后我尝试在branches_services表中按出价对branches_services.sid和services.sid进行分组所以我可以找到服务表中的客户服务费大于2000的费用。
select cname from clients where cid in
(select cid from branches where bid in (select branches_services.sid, services.sid
from branches_services, services
where branches_services.sid=services.sid group by bid having sum(sfee) >= 2000));
ERROR 1241(21000):操作数应包含1列
答案 0 :(得分:0)
您的一个子查询返回两列,但您只使用一个值来检查是否在返回的值对中找到它。这里:
....bid in (select branches_services.sid, services.sid
from branches_services, services ...
因此,假设branches_services表具有列bid
,则查询应为:
select cname from clients
where cid in
(select cid from branches
where bid in
(select branches_services.bid from branches_services join services
on branches_services.sid=services.sid
group by bid
having sum(sfee)>=2000));