MySQL 错误:子查询返回超过 1 行

发布于 2024-10-17 14:16:04 字数 521 浏览 3 评论 0原文

子查询返回超过 1 行

出现错误:#1242 -执行此操作时

SELECT `Index` , `FundName` ,Count(*), 
    (SELECT COALESCE(sum(b.PricePerWeek),0) 
     FROM tbl_FundSubscriptions
     WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= SubscribeDt  
     GROUP BY FundIDSend)

FROM tbl_FundSubscriptions b, tbl_FundStatic a

WHERE a.FundID = b.FundIDSend

AND FundIDSend IN 
    (SELECT FundID
     FROM tbl_FundStatic
     WHERE UserID = '14')

GROUP BY a.FundName,a.Index 

可能出了什么问题?

谢谢

Getting error : #1242 - Subquery returns more than 1 row

while executing this

SELECT `Index` , `FundName` ,Count(*), 
    (SELECT COALESCE(sum(b.PricePerWeek),0) 
     FROM tbl_FundSubscriptions
     WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= SubscribeDt  
     GROUP BY FundIDSend)

FROM tbl_FundSubscriptions b, tbl_FundStatic a

WHERE a.FundID = b.FundIDSend

AND FundIDSend IN 
    (SELECT FundID
     FROM tbl_FundStatic
     WHERE UserID = '14')

GROUP BY a.FundName,a.Index 

What could be wrong?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2024-10-24 14:16:04

这是您要查找的查询吗?不知道您的表结构,我们永远不会知道,但这会执行您的查询似乎已缩进的操作。 (这有什么意义吗?)

SELECT `Index`, `FundName`, COUNT(*), 
    (SELECT SUM(`PricePerWeek`)
     FROM `tbl_FundSubscriptions`
     WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= `SubscribeDt` 
           AND `FundIDSend` = `tbl_FundStatic`.`FundID`)

FROM `tbl_FundStatic`

WHERE `UserID` = '14'

Is this the query you're looking for? Not knowing your table structure, we'll never know, but this does what your query appears to have been indented to do. (Does that make any sense at all?)

SELECT `Index`, `FundName`, COUNT(*), 
    (SELECT SUM(`PricePerWeek`)
     FROM `tbl_FundSubscriptions`
     WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) <= `SubscribeDt` 
           AND `FundIDSend` = `tbl_FundStatic`.`FundID`)

FROM `tbl_FundStatic`

WHERE `UserID` = '14'
情感失落者 2024-10-24 14:16:04

您的子查询返回的行数超过 1 行。

您可以将子查询LIMIT到一行,或者将其与另一个表LEFT JOIN

Your subquery is returning more then 1 row.

Either you LIMIT the subquery to one row or you LEFT JOIN it with the other table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文