MySQL子查询错误ERROR 1242(21000):子查询返回多于1行

时间:2014-01-06 16:57:26

标签: mysql sql

您好,我想通过查询中的mcap来查询我的查询,但是我收到了错误,我用谷歌搜索但找不到合适的解决方案。这是查询:

SELECT 

 c.code,
(e.total_value - 
IFNULL((SELECT total_value FROM eod_stock WHERE company_id = e.company_id AND entry_date =  

SELECT 
entry_date FROM eod_stock WHERE entry_date < e.entry_date AND company_id = e.company_id ORDER  

BY entry_date DESC LIMIT 0,1)),0))/

(SELECT total_value FROM eod_stock WHERE company_id = e.company_id AND entry_date = (SELECT entry_date FROM eod_stock WHERE entry_date < e.entry_date AND company_id = e.company_id ORDER BY entry_date DESC LIMIT 0,1)) AS turnover_growth,

(SELECT total_share FROM share_percentage WHERE company_code = c.code) * e.ltp AS mcap,

'' AS pe

 -- ,e.*

FROM eod_stock AS e

LEFT OUTER JOIN company AS c

ON c.ID = e.company_id

WHERE e.company_id AND e.entry_date = (SELECT MAX(entry_date) FROM eod_stock)

ORDER BY mcap DESC

LIMIT 0,10;

但它返回错误:

ERROR 1242 (21000): Subquery returns more than 1 row

不知道出了什么问题。任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

唯一不是全局聚合或具有限制子句的子查询是:

(SELECT total_share FROM share_percentage WHERE company_code = c.code)

我猜这会返回多行。

编辑:

你是如何解决的?这取决于逻辑。以下两种方式对我来说很合理:

(SELECT sum(total_share) FROM share_percentage WHERE company_code = c.code)

(SELECT total_share FROM share_percentage WHERE company_code = c.code limit 1)