MySQL 错误:子查询返回多于一行 [英] MySQL Error: Subquery returns more than one row

查看:47
本文介绍了MySQL 错误:子查询返回多于一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的查询中,我获取了三列(比如 A、B 和摘要)

In my query I am fetching three columns (say A,B and Summary)

总结基于 B 和 A.

Summary is based on B and A.

我必须使用子查询来获取基于 A 和 B 的摘要.

I have to use a subquery to fetch Summary based on A and B.

问题:

对于 A 的一个值(比如 A1)和 B 的一个值(比如 B1),我在一个列中得到两个摘要值(比如 Summ1 和 Summ2).

For one value of A (say A1) and one value of B (say B1), I get two values of Summary (say Summ1 and Summ2) in One column.

因此它给出了错误:

 Subquery returns more than one row 

相反,我想在我的表格中显示如下:

Instead I want to show it as below in my table:

 A1     B1     Summ1
 A1     B1     Summ2  

我该怎么做?

查询:

SELECT a.FundIDRecv,a.SubscribeDt, b.FundName, 
(
   SELECT c.PricePerWeek
   FROM tbl_Hive c
   WHERE c.FundID IN 
   (
      SELECT FundID from tbl_FundStatic 
      WHERE FundID IN
      (
          SELECT FundIDSend
          FROM tbl_FundSubscriptions 
          WHERE FundIDRecv = a.FundIDRecv

      )
      AND UserID = '14'
   )
) as Price
FROM tbl_FundSubscriptions a, tbl_Hive b
WHERE a.FundIDRecv = b.FundID

AND a.FundIDRecv
IN (

SELECT FundIDRecv
FROM tbl_FundSubscriptions
WHERE FundIDSend
IN (

SELECT FundID
FROM tbl_FundStatic 
WHERE UserID = '14'
)
)
Group by a.FundIDRecv

c.PricePerWeek 的 SELECT 语句产生该错误

SELECT statement for c.PricePerWeek generates that error

推荐答案

听起来您需要将其重组为 JOIN 而不是子查询.

It sounds like you need to restructure it as a JOIN rather than a subquery.

这篇关于MySQL 错误:子查询返回多于一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆