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 7218859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:32:25+00:00 2026-05-28T21:32:25+00:00

I want to compare and count rows in the same datatabe. myDataTable hours_id(PK) |

  • 0

I want to compare and count rows in the same datatabe.

myDataTable

hours_id(PK) | _person_id | _project_id | date_of_hour
 1       |    pe1     |    pr1      | 13.10.2011
 2       |    pe22    |    pr1      | 13.10.2011
 3       |    pe1     |    pr1      | 15.10.2011 *
 4       |    pe1     |    pr1      | 13.10.2011
 5       |    pe1     |    pr1      | 13.10.2011
 6       |    pe22    |    pr22     | 13.10.2011
 7       |    pe1     |    pr22     | 15.10.2011 *
 8       |    pe1     |    pr1      | 15.10.2011 *
 9       |    pe22    |    pr22     | 13.10.2011
 10      |    pe22    |    pr22     | 13.10.2011
 11      |    pe1     |    pr1      | 16.10.2011 **

_project_id(GUID)

In my program I can choose _person_id_2 = pe1, date_of_begin = 13.10.2011 and date_of_end = 15.10.2011. I want to get this result:

 pe1    pr1   13.10.2011  3   //(count 3 rows are the same)(ROWS 1,4,5)
 pe1    pr1   15.10.2011  2   //(ROWS 3,8)
 pe1    pr22  15.10.2011  1   //(ROW 7)

And when I choose _person_id_2 = pe22, date_of_begin = 13.10.2011 and date_of_end = 15.10.2011 I want to get this result:

 pe22   pr1   13.10.2011  1   //(ROW 2)
 pe22   pr22  13.10.2011  1   //(ROW 6)
 pe22   pr22  15.10.2011  2   //(ROWS 9,10)

I’m using SQL Server 2008. Hope you understand what I’m trying to ask.

  • 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-28T21:32:25+00:00Added an answer on May 28, 2026 at 9:32 pm

    Do you need a group by clause + count aggregation function:

    Select 
       _person_id, _project_id, date_of_hour, count(*)
    from
       myDataTable
    where 
       _person_id = 'pe1'
     and
       date_of_hour between '13.10.2011' and '15.10.2011'
    group by 
     _person_id, _project_id, date_of_hour
    

    Notice: I understand that when you write ‘13.10.2011’ you are talking about a well formed date and date_of_hour is in date or datetime format. If is not the case, you should cast your strings and columns to a valid date.

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

Sidebar

Related Questions

I want to compare two tables based on their total number of rows. So
I want to compare the current value of an in-memory Hibernate entity with the
I want to compare two ms-access .mdb files to check that the data they
I want to compare and contrast the various source control systems out there. Any
I want to compare the first few bytes in byte[] with a string. How
I want to compare records between 2 databases on my SQL 2008 Server. The
We want to compare general performance (CPU, I/O, network, ...) of different JVMs for
I want to compare two CSV files to see if they are different. I
I want to compare two times in VB.net: I have 1:42:21 PM and I
I want to compare two arrays, one coming from a shoppingcart and the other

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.