如何在两个日期之间获取值,日期之间的间隔为10分钟

时间:2016-02-18 07:30:38

标签: sql-server sql-server-2008

SELECT 
    t0.brandID,
    t0.brandName,
    t0.cdt,
    t0.udt,
    t0.brandstatus,
    (DATEPART(MINUTE, t0.cdt)) as tempt
FROM brands t0 
WHERE 
    CONVERT(VARCHAR(10),t0.cdt,110) BETWEEN 
        CONVERT(VARCHAR(10),'01-11-2013',110) and CONVERT(VARCHAR(10),'11-11-2014',110)

以上查询给出了日期之间的值。我希望每10分钟获得这些日期之间的值。

brandID brandName   cdt                     udt                         brandstatus tempt
1       khasim      2013-11-01 19:14:18.123 2013-11-15 19:14:18.123     1           14
3       khasim      2013-11-02 19:17:57.700 2013-11-15 19:17:57.700     1           17
4       tanveer     2013-11-03 19:18:05.947 2013-11-15 19:18:05.947     1           18
5       abcdef      2013-11-04 20:50:06.783 2013-11-15 20:50:06.787     1           50
8       budwieser   2014-02-12 19:26:43.913 2014-02-12 19:26:43.913     1           26

预期结果:(选择日期为15-11-2013和16-11-2013之间的日期)

    brandid brandname cdt udt
    1        khasim   2013-11-15 (00:00:01)---first record created on that date
    2        somethi  2013-11-15 (00:00:05)---second record

...
...  
final record at (00:10:00) minutes...

需要计算所选日期之间10分钟间隔的数量,并且每10分钟间隔需要获得记录。

0 个答案:

没有答案