Time, Count(Hits)

  • Can you post the 12 records here?

     


    N 56°04'39.16"
    E 12°55'05.25"

  • Please see post 10. following are 12 hits logged in to LoginTrack table for 01-Jan-2007 with the help of following query:

    Declare

     @todate datetime, 

     @fromdate datetime, 

     @channelid numeric(9)

     

    set @todate = '01/01/2007'

    set @fromdate = '01/01/2007'

    select LoginDateTime from LoginTrack

    where convert (varchar, LoginDateTime,101) between @fromdate and @todate

    order by LoginDateTime

    No.Login_datetime
    12007-01-01 04:00:00.000
    22007-01-01 08:00:00.000
    32007-01-01 09:00:00.000
    42007-01-01 10:26:18.503
    52007-01-01 11:00:00.000
    62007-01-01 11:00:00.000
    72007-01-01 11:00:00.000
    82007-01-01 14:00:00.000
    92007-01-01 14:52:27.817
    102007-01-01 16:00:00.000
    112007-01-01 22:00:00.000
    122007-01-01 23:00:00.000

    there are total 12 hits on 01-Jan-2007, but the result is giving me 1 more hit for 22:00 to 23:00, see below: also the percent becomes above 100.

    <TD class=xl24 style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent" align=right x:num x:fmla="=SUM(D224)">13

    No.Hit DurationPercentHits
    100:00 to 01:0000
    201:00 to 02:0000
    302:00 to 03:0000
    403:00 to 04:0000
    504:00 to 05:008.331
    605:00 to 06:0000
    706:00 to 07:0000
    807:00 to 08:0000
    908:00 to 09:008.331
    1009:00 to 10:008.331
    1110:00 to 11:008.331
    1211:00 to 12:00253
    1312:00 to 13:0000
    1413:00 to 14:0000
    1514:00 to 15:0016.672
    1615:00 to 16:0000
    1716:00 to 17:008.331
    1817:00 to 18:0000
    1918:00 to 19:0000
    2019:00 to 20:0000
    2221:00 to 22:0000
    2322:00 to 23:0016.672should be 1
    2423:00 to 00:008.331
    your query results:108.32
    it should be10012

    DECLARE     @ToDate DATETIME,

                @FromDate DATETIME,

                @ChannelID NUMERIC(9)

     

    SELECT      @ToDate = '01/01/2007',

                @FromDate = '01/01/2007'

     

    SELECT      v.Number + 1 AS Hit,

                CONVERT(CHAR(5), DATEADD(HOUR, v.Number, 0), 108) + ' to ' + CONVERT(CHAR(5), DATEADD(HOUR, v.Number + 1, 0), 108) AS [Hit Duration],

                CONVERT(DECIMAL(5, 2), 100.0 * COUNT(lt.LoginDateTime) / t.h) AS [Percent],

                COUNT(lt.LoginDateTime) AS Hits

    FROM        (

                             SELECT 0 AS Number UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL

                            SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL

                            SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL

                            SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL

                            SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL

                            SELECT 22 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23

                ) AS v

    CROSS JOIN  (

                            SELECT      COUNT(*) AS h

                            FROM        LoginTrack

                            WHERE       LoginDateTime >= @FromDate

                                         AND LoginDateTime < DATEADD(DAY, 1, @ToDate)

                ) AS t

    LEFT JOIN   LoginTrack AS lt ON DATEPART(HOUR, lt.LoginDateTime) = v.Number

                            AND lt.LoginDateTime >= @FromDate

                            AND lt.LoginDateTime < DATEADD(DAY, 1, @ToDate)

    GROUP BY    v.Number,

                t.h

    ORDER BY    v.Number

     Shamshad Ali.

  • Peter, I found out the clue, here was a little mistake making V table

    the last row of populating v table was missing 20 and it was 22 twice.

    Old:

    From

    (

                            SELECT 0 AS Number UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL

                            SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL

                            SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL

                            SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL

                            SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL

                            SELECT 22 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23

                ) AS v

    New:

    From

    (

                            SELECT 0 AS Number UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL

                            SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL

                            SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10 UNION ALL SELECT 11 UNION ALL

                            SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL SELECT 15 UNION ALL

                            SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL

                            SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23

                ) AS v

     

    Thanks for such GREAT!!! support, its now working perfect.

     

    Shamshad Ali.

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply