mysql - My sql query with MAX, MIN and third field for HAVING -
i'm trying minimum , maximum price on mysql(myisam) query. i'm using query for:
select max(price_feed) max, min(price_feed) min, sqrt( pow(69.1 * (latitude_feed - 51.542980), 2) + pow(69.1 * (-0.149323 - longitude_feed ) * cos(latitude_feed / 57.3), 2)) distance feed listing_type_feed = 'rental' , property_type_feed in ("flat", "apartament", "penthouse", "studio") having distance < 2
but returns nothing, while when try
select price_feed max, price_feed min, sqrt( pow(69.1 * (latitude_feed - 51.542980), 2) + pow(69.1 * (-0.149323 - longitude_feed ) * cos(latitude_feed / 57.3), 2)) distance feed listing_type_feed = 'rental' , property_type_feed in ("flat", "apartament", "penthouse", "studio") having distance < 2
it returns 2600 rows. thanks
you need nested query or cte depending on rdbms
first calculate property in 2km radius , calculate max/min prices result, dont need having
instead use where
clausule
select max(price_feed) max, min(price_feed) min ( select price_feed feed listing_type_feed = 'rental' , property_type_feed in ("flat", "apartament", "penthouse", "studio") , sqrt( pow(69.1 * (latitude_feed - 51.542980), 2) + pow(69.1 * (-0.149323 - longitude_feed ) * cos(latitude_feed / 57.3), 2)) < 2 ) filter_properties
Comments
Post a Comment