mysql - Can't solve this sql statement to archive my real goal -
select hotel.hotel_id, hotel.hotel_name, hotel.hotel_address, hotel.hotel_pic, room_accommodation.room_full_price hotel inner join room_accommodation on (room_accommodation.hotel_id = hotel.hotel_id ) inner join ( select min( room_full_price ) minprice room_accommodation inner join hotel on ( hotel.hotel_id =room_accommodation.hotel_id ) hotel.hotel_address '%bangkok%' )room_accommodation on room_accommodation.room_full_price = room_accommodation.minprice
this sql can query each hotel in bangkok lowest rate of each hotel
but problem want query lowest rate of each hotel when cut
the condition out result gave me 1 lowest price of hotel
what wrong , should archive this
please advice
thank in advance.
this can simplified - there's no need subquery based on results need:
select hotel.hotel_id, hotel.hotel_name, hotel.hotel_address, hotel.hotel_pic, min(room_accommodation.room_full_price) room_full_price hotel inner join room_accommodation on room_accommodation.hotel_id = hotel.hotel_id , hotel.hotel_address '%bangkok%' group hotel.hotel_id
note other dbms's need specify each non-aggregate field in group clause. mysql lets away without - better or worse.
Comments
Post a Comment