gpt4 book ai didi

MySQL子查询错误ERROR 1242 (21000) : Subquery returns more than 1 row

转载 作者:行者123 更新时间:2023-11-29 13:20:06 27 4
gpt4 key购买 nike

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

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

不知道出了什么问题。谁能帮我吗?

最佳答案

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

(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)

关于MySQL子查询错误ERROR 1242 (21000) : Subquery returns more than 1 row,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20955101/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com