-1

私はこの仕事をするのに苦労しています、このクエリは2つの日付の間で最も安い価格で取引を与えるはずですが、どういうわけかそれは常に最も安いオファーを与えており、それはちょっと日付を無視します

SELECT offer_id 
FROM travel_offers o
WHERE price = (
    SELECT MIN(price) as minprice 
    FROM travel_offers om 
    WHERE 
        o.latitude = om.latitude AND
        o.longitude = om.longitude AND
        (o.time_from BETWEEN '2012-07-01' AND '2012-11-31') 
        AND
        (o.time_to BETWEEN '2012-07-01' AND '2012-11-31')
)
4

3 に答える 3

0

経度と緯度が重要な場合は、これを試してください。

SELECT o.longitude, o.latitude, offer_id 
FROM travel_offers o
WHERE o.time_from BETWEEN '2012-07-01' AND '2012-11-31'
      AND o.time_to BETWEEN '2012-07-01' AND '2012-11-31')
      AND price = (
     SELECT MIN(price) as minprice 
     FROM travel_offers om 
     WHERE 
        o.latitude = om.latitude AND
        o.longitude = om.longitude AND
        (om.time_from BETWEEN '2012-07-01' AND '2012-11-31') 
        AND
        (om.time_to BETWEEN '2012-07-01' AND '2012-11-31')
)

経度と緯度が重要でない場合:

SELECT offer_id 
FROM travel_offers o
WHERE o.time_from BETWEEN '2012-07-01' AND '2012-11-31'
      AND o.time_to BETWEEN '2012-07-01' AND '2012-11-31')
      AND price = (
     SELECT MIN(price) as minprice 
     FROM travel_offers om 
     WHERE 
        (om.time_from BETWEEN '2012-07-01' AND '2012-11-31') 
        AND
        (om.time_to BETWEEN '2012-07-01' AND '2012-11-31')
)
于 2012-09-18T14:16:04.737 に答える
0

どういうわけかそれは常に最も安いオファーを与えており、それはちょっと日付を無視します

私はあなた1time_fromがそうあるべきで2012-07-01あり、time_toそうあるべきだと思います2012-11-31。したがって、次のような句の
条件を修正する必要があります。WHERE1time_from1time_to

WHERE 
    o.latitude = om.latitude AND
    o.longitude = om.longitude AND
    (o.time_from >= '2012-07-01') 
    AND
    (o.time_to <= '2012-11-31')
于 2012-09-18T14:16:15.270 に答える
0
SELECT offer_id, MIN(price) as minprice 
FROM travel_offers
WHERE 
    time_from BETWEEN '2012-07-01' AND '2012-11-31'
    AND
    time_to BETWEEN '2012-07-01' AND '2012-11-31'
    and 
    time_from <= time_to
group by offer_id
order by minprice
limit 1
于 2012-09-18T14:12:15.750 に答える