テーブル内に、Auctions
という列がありますAuction_StartDate
。行の値は次のようになります2012-10-27 13:45:30
。
その後、次に近い日付と時刻を返すクエリが必要です。したがって、次の Auction_StartDate が2012-10-27 18:30:00
である場合、日付が になる前にそれを返す必要があります2012-10-28
。
テーブル内に、Auctions
という列がありますAuction_StartDate
。行の値は次のようになります2012-10-27 13:45:30
。
その後、次に近い日付と時刻を返すクエリが必要です。したがって、次の Auction_StartDate が2012-10-27 18:30:00
である場合、日付が になる前にそれを返す必要があります2012-10-28
。
句MIN
を使用せずに、を使用して最も近い値を見つけることができます。LIMIT and ORDER BY
SELECT MIN(DATE(Auction_StartDate)) closestDate
FROM Auctions
WHERE DATE(Auction_StartDate) > '2012-10-27'
すべての行に対してこれを行う場合は、次のことを試してください。
SELECT a1.id,
(SELECT MIN(a2.Auction_StartDate)
FROM Auctions a2
WHERE a2.Auction_StartDate > a1.Auction_StartDate) AS nextStartDate
FROM Auctions a1
これが役立つかもしれません
SELECT DATE(Auction_StartDate) closestDate
FROM Auctions
WHERE DATE(Auction_StartDate) > '2012-10-27'
order by Auction_StartDate ASC
limit 1
SELECT (case when Hour(StartDate)>=12 then DATE_ADD(StartDate,
INTERVAL 1 DAY) else StartDate end) as 'date' FROM table
------------------------------
pleaes add your column name where is static date :
est on : http://sqlfiddle.com/#!2/b8435/19
SELECT (case when Hour(StartDate )>=12 then
DATE_FORMAT( DATE_ADD(StartDate ,INTERVAL 1 DAY), '%Y-%m-%d')
else DATE_FORMAT(StartDate , '%Y-%m-%d') end) as 'date' from tabel