子查询使用group by返回超过1行的问题

时间:2015-05-21 11:49:28

标签: mysql

请帮助我解决下面的查询错误,我得到"子查询返回超过1行"

select
count(*) NONGENACC,  AFFILIATE,
(SELECT COUNT(ACCOUNTNO) from realdb.tbl_logs GROUP BY AFFILIATE )AS ALLACCS
FROM  realdb.tbl_logs
where LASTDATE <> CURDATE() group by AFFILIATE

当我从子查询中获取GROUP BY而不是我想要的allacs字段时,它返回以下内容。请帮助...

NONGENACC AFFILIATE      ALLACCS 
1         ECOCBFBF        1481 
2         ECOCBIBI        1481 
13        ECOCBJBJ        1481 
11        ECOCCDKI        1481 
3         ECOCCFCF        1481 

2 个答案:

答案 0 :(得分:0)

尝试从子查询中删除$scope.myViewModel = { delete1: function () { alert("test"); } }; 。 所以你最终的查询将如下所示:

GROUP BY AFFILIATE

答案 1 :(得分:0)

好的,谢谢大家的消遣。我通过使用下面的查询来获得我想要的结果:

  SELECT AFFILIATE, 'TotalAccounts', count(accountno)
  FROM realdb.tbl_logs
  GROUP BY AFFILIATE
  UNION ALL
  SELECT AFFILIATE, 'MissingAccount', count(accountno)
  FROM realdb.tbl_logs
  WHERE LASTDATE <> CURDATE() 
  GROUP BY AFFILIATE 
  ORDER BY 1, 2 DESC