我在一个MySQL数据库中有两个表,定期添加新数据。一份是出租物业清单及其特点,如2张床、2间浴室、地点、租金等。第二张表是目前待售的物业清单。从租房表中,我可以使用查询确定特定类型的财产在特定位置的平均租金:
SELECT bed, bath, type, suburb, postcode, AVG(price)
FROM rent_suburbs
GROUP BY bed, bath, type, suburb, postcode我希望能够从buy_items表中选择属性,其中用户定义的销售价格百分比低于匹配类型和位置的属性的平均租赁价格。
我试图修复下面的代码,有人建议,但我被困住了。
select listing, bed, bath, type, address, postcode, state, price
from
buy_items
where (price*.0014) < avg(price) from
select
bed, bath, type, suburb, postcode, avg(price)
from
rent_items
group by bed , bath , type , suburb , postcode
/* and bed, bath, type, suburb and postcode match the buy_items property ????我是新来的,所以任何帮助都很感激。谢谢
表的结构如下:
buy_items
buy_items_id2 int(11)
car int(11)
price int(11)
listing varchar(12)
bed int(11)
bath int(11)
suburb varchar(25)
state int(11)
scrapedate int(11)
address varchar(45)
type varchar(25)
postcode int(11)和
rent_items
rent_items_id2 int(11)
car int(11)
price int(11)
listing int(11)
bed int(11)
bath int(11)
suburb varchar(25)
state varchar(5)
scrapedate int(11)
address varchar(45)
type varchar(25)
postcode int(11)发布于 2013-11-05 13:24:40
试试这个:
select listing, b.bed, bath, type, address, postcode, state, price
from
buy_items b
join (
SELECT bed, bath, type, suburb, postcode, AVG(price) as avg_price
FROM rent_suburbs
GROUP BY bed, bath, type, suburb, postcode ) a
on a.bed=b.bed and a.bath=b.bath and a.suburb=b.suburb and a.postcode=b.postcode
where (b.price*.0014) < a.avg_price;https://stackoverflow.com/questions/19788717
复制相似问题