0

在我的Auctions桌子里面,我有一列叫做Auction_StartDate. 一行的值是这样的:2012-10-27 13:45:30.

我需要一个查询,该查询将在此之后返回下一个最接近的日期和时间。因此,如果下一个 Auction_StartDate 是2012-10-27 18:30:00,它应该在日期变为 之前返回2012-10-28

4

4 回答 4

1

您可以在不使用子句MIN的情况下使用查找最接近的值。LIMIT and ORDER BY

SELECT  MIN(DATE(Auction_StartDate)) closestDate
FROM    Auctions
WHERE   DATE(Auction_StartDate) > '2012-10-27'

SQLfiddle 演示

于 2012-10-11T05:51:17.157 回答
1

如果您打算对每一行都执行此操作,请尝试以下操作:

SELECT a1.id,
    (SELECT MIN(a2.Auction_StartDate) 
     FROM Auctions a2 
     WHERE a2.Auction_StartDate > a1.Auction_StartDate) AS nextStartDate
FROM Auctions a1
于 2012-10-11T05:52:23.740 回答
0

可能这个有帮助

    SELECT DATE(Auction_StartDate) closestDate
    FROM    Auctions
    WHERE   DATE(Auction_StartDate) > '2012-10-27'
    order by Auction_StartDate ASC
    limit 1
于 2012-10-11T05:55:30.940 回答
0
   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 
于 2012-10-11T05:59:38.290 回答