Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7399305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:02:38+00:00 2026-05-29T04:02:38+00:00

I have a security log table with 4 cols: UserID, LOGINDate, LOGINTime, ClickEvents Now

  • 0

I have a security log table with 4 cols:

UserID, LOGINDate, LOGINTime, ClickEvents

Now I am trying to get a hourly traffic table for past 7 days, which is like:

   DAY1 |  DAY2 | DAY3 |  DAY4 |.... |DAY7
1   0   |    1  |   12 |  4567 |     | 43
2
3
4
5
:
:
24

can you show me or give me some idea how to make this table by using SQL?


marc_s Thanks for your quick reply. what I have now is :

select  LOGINDate, SUBSTRING(LOGINTime, 1, 2) as 'HoTime', COUNT( *)
From SECLOG
where (CONVERT(varchar( 8) , GETDATE()-7, 112) <= LOGINDate)

group by LOGINDate, SUBSTRING(LOGINTime, 1, 2)
order by LOGINDate, HoTime

which produces me a table like

DATE | HoTime | No of
0926 | 1      | 2
0926 | 2      | 4
0926 | 14     | 6

also it skips the hour without no data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:02:38+00:00Added an answer on May 29, 2026 at 4:02 am

    First do a query that groups by date and hour summing the click events for each hour for the last 7 days.
    Then you need to pivot that result so you get the days as a columns. That can be done with a group by on hour and using a case statement in the field list testing for the day number.

    To get zero as a value when there are no events in an hour you can use a numbers table that return 1-24 and left join your result set.

    Something like this for SQL Server 2008 where you have the date data type.

    with C as
    (
      select datediff(day, LoginDate, getdate()) as DD, 
             LoginTime,
             sum(ClickEvents) as ClickEvents
      from YourTable
      where LoginDate >= dateadd(day, -7, cast(getdate() as date))
      group by LoginDate, LoginTime
    ), H as
    (
      select 1 as LoginTime
      union all
      select H.LoginTime+1
      from H
      where H.LoginTime < 24
    )  
    select H.LoginTime, 
           sum(case DD when 1 then C.ClickEvents else 0 end) as Day1,
           sum(case DD when 2 then C.ClickEvents else 0 end) as Day2,
           sum(case DD when 3 then C.ClickEvents else 0 end) as Day3,
           sum(case DD when 4 then C.ClickEvents else 0 end) as Day4,
           sum(case DD when 5 then C.ClickEvents else 0 end) as Day5,
           sum(case DD when 6 then C.ClickEvents else 0 end) as Day6,
           sum(case DD when 7 then C.ClickEvents else 0 end) as Day7
    from H
      left outer join C
        on C.LoginTime = H.LoginTime
    group by H.LoginTime
    order by H.LoginTime;
    

    Try it on SE Data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java web application that use spring security for log in users,
I have written simple application with container-managed security. The problem is when I log
Do Pagemethods and Json have security risks?(I dont use cookies).Forexample i have a pagemethod
I have a security consultant demanding that we implement encrypted connections to mySQL. He
I have some security related service running on my machine (start type = automatic)
I have a security number generator device, small enough to go on a key-ring,
Is it possible to have transport security without authentication? I'm well aware of it's
Is there a way to see users that have certain security role assigned? I'm
As many of you probably know, online banks nowadays have a security system whereby
I have used spring security 3.0.7 and I am implementing concurrency control in my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.