SQL: select *错误,麻烦帮我看看怎么回事,怎么解决呢

SQL:
select *,(select credit1 from `ims_mc_members` where uid=s.openid ) as surplus,(select followtime from `ims_mc_mapping_fans` where uid=s.openid and follow='1') as follow from `ims_tiger_jifenbao_share` s where openid<>'' and weid='5' and status=0 order by createtime desc LIMIT 0,10

Params:
array ( )
SQL Error:
Subquery returns more than 1 row
Traces:
file: /framework/class/db.class.php; line: 158;
file: /framework/function/pdo.func.php; line: 44;
file: /addons/tiger_jifenbao/site.php; line: 165;
file: /web/source/site/entry.ctrl.php; line: 81;
file: /web/index.php; line: 239;

(select credit1 from `ims_mc_members` where uid=s.openid ) as surplus,

(select followtime from `ims_mc_mapping_fans` where uid=s.openid and follow='1') as follow

你这两个子查询中某一个查出了多条值,系统不知道你要取哪个。

你可以简单的查询下异常数据:

select uid from `ims_mc_members`  group by uid having count(uid)>1

select uid from `ims_mc_mapping_fans` where  follow='1' group by uid having count(uid)>1

可以通过这两条语句确认你上边两个子查询的表里可能是哪些数据UID重复了

要解决这种情况(不考虑你上边因为数据问题导致的)有几种改写:

    两个子查询里的where条件要更加精确,确保`ims_mc_members` where uid=s.openid和`ims_mc_mapping_fans` where uid=s.openid and follow='1'更加精确

    如果确认有多条,优先取"大"的那条,就可以使用max等聚合函数

    select *,(select max(credit1) from `ims_mc_members` where uid=s.openid ) as surplus,(select max(followtime) from `ims_mc_mapping_fans` where uid=s.openid and follow='1') as follow from `ims_tiger_jifenbao_share` s where openid<>'' and weid='5' and status=0 order by createtime desc LIMIT 0,10

    使用left join然后on和where控制,有点类似于第1条

温馨提示:答案为网友推荐,仅供参考
相似回答