mysql 子查询 不在_MySQL Group不在子查询中工作

我有这个查询,效果很好.我使用MIN(home_price)显示作为起始价格,我使用此查询为api和WHERE子句添加到它,所以如果我按价格搜索MIN(home_price)更改.

SELECT MIN(home_price) as min_home_price,

id,

name,

community,

maplocation,

locationLabel,

logo

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

INNER JOIN rb_locations

ON readyBuilt.home_location = rb_locations.locationId

WHERE id IN ( SELECT DISTINCT id

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

WHERE isDeleted = 0 AND is_upcoming = 0)

AND home_status = 1

GROUP BY id,name,community,mapLocation,locationLabel,logo

ORDER BY name

所以我的解决方案是使用子查询

SELECT id,

name,

community,

maplocation,

locationLabel,

logo,

(SELECT MIN(home_price) as min_home_price

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

INNER JOIN rb_locations

ON readyBuilt.home_location = rb_locations.locationId

WHERE id IN ( SELECT DISTINCT id

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

WHERE isDeleted = 0

AND is_upcoming = 0)

AND home_status = 1

GROUP BY id,name,community,mapLocation,locationLabel,logo

ORDER BY name) as org_min_home_price

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

INNER JOIN rb_locations

ON readyBuilt.home_location = rb_locations.locationId

WHERE id IN ( SELECT DISTINCT id

FROM ourCommunity

INNER JOIN readyBuilt

ON community = home_community

WHERE isDeleted = 0 AND is_upcoming = 0)

AND home_status = 1

GROUP BY id,name,community,mapLocation,locationLabel,logo

ORDER BY name

但是当我执行第二个查询时,我收到此错误

Subquery returns more than 1 row

当我删除GROUP BY时,MIN(home_price)没有错误,每行都是相同的.有没有人对如何完成我想要完成的事情有任何建议?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值