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

  • Home
  • SEARCH
  • 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 8006467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:31:28+00:00 2026-06-04T17:31:28+00:00

I am working with sql database, and I have problem. It is about public

  • 0

I am working with sql database, and I have problem. It is about public transportation, and I have table ‘Traffic accidents’ and column ‘Time when accident happened’ (datetime). I need to count how many accidents happened in specific HOUR, to realize what is the most risking part of day.
I know how to separate hour from datetime, but the problem is how to count and order..
It should be something like this:

Time of traffic accidents

 2011-03-05 07:40:00.000,        
 2011-03-07 01:15:00.000,      
 2011-04-07 19:00:00.000,      
 2011-07-23 11:00:00.000,        
 2011-06-22 07:09:00.000,
 2011-03-08 07:14:00.000,
 2011-02-02 01:26:00.000  

Order accidents by hour

7h- 3 accidents,
1h- 2 accidents,
6h- 1 accident,
etc…

My English is not perfect, but I hope that I was clear enough 😛
Thank you, Urosh

  • 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-06-04T17:31:30+00:00Added an answer on June 4, 2026 at 5:31 pm

    try something like this:

    WITH T as
    (
     SELECT '2011-03-05 07:40:00.000' Col1 UNION ALL        
     SELECT '2011-03-07 01:15:00.000' Col1 UNION ALL  
     SELECT '2011-04-07 19:00:00.000' Col1 UNION ALL        
     SELECT '2011-07-23 11:00:00.000' Col1 UNION ALL          
     SELECT '2011-06-22 07:09:00.000' Col1 UNION ALL  
     SELECT '2011-03-08 07:14:00.000' Col1 UNION ALL  
     SELECT '2011-02-02 01:26:00.000' 
    ) 
    

    Suppose T is your Table and Col1 is your datecolumn.

    SELECT DATEPART(hour,Col1) as Hour,COUNT(DATEPART(hour,Col1)) as Accidents FROM T
    GROUP BY DATEPART(hour,Col1)
    ORDER BY DATEPART(hour,Col1)
    

    Result:

    Hour Accidents
    1    2
    7    3
    11   1
    19   1
    

    Best Regards

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

Sidebar

Related Questions

I have a database working in my local sql server 2005 express edition. I
I am working on PHP and database MySQL. I have two tables in SQL
I have a problem in writing sql query. Here is the illustration about my
I have a windows application working with a SQL Compact 4.0 database, using EF
I have written a working T-SQL MERGE statement. The premise is that Database A
I have a problem with a large database I am working with which resides
I am working on an Excel application that queries a SQL database. The queries
I'm working on a SQL Server 2008 database. This database has two tables. Book
I am working with SQL Server and I want to set the Database password
I'm working on an ASP (Classic) application using MS SQL as database. In the

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.