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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:29:01+00:00 2026-06-17T19:29:01+00:00

I am trying to show a count for each age which is calculated from

  • 0

I am trying to show a count for each age which is calculated from a Date of Birth column but the problem is it will only group by date of birth so there are a lot of duplicate ages being shown. Here is my query:

SELECT 
    DATEDIFF(hh, p.p_dob, GETDATE())/8766 AS Age,
    COUNT(DISTINCT s.s_studentreference) AS 'Count'    
FROM 
    moduleenrolment e
INNER JOIN 
    module m ON m.m_id = e.e_module
INNER JOIN 
    person p ON p.p_id = e.e_student
INNER JOIN 
    student s ON s.s_id = p.p_id
WHERE 
    m.m_reference LIKE '11%'
    AND LEN(m.m_reference) <= 12
    AND e.e_status IN ('A', 'W', 'C')
GROUP BY 
    p.p_dob
ORDER BY 
    p.p_dob DESC

This is a sample for the results

12  1
13  1
14  1
14  1
14  1
14  1
14  1
14  1
14  1
14  1
14  1

What I was looking for was

12 1
13 1
14 9
  • 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-17T19:29:02+00:00Added an answer on June 17, 2026 at 7:29 pm

    Group by and order by DATEDIFF(hh, p.p_dob, GETDATE())/8766 instead of p.p_dob

    By grouping by p.p_dob, you’re effectively grouping by the unique date of birth instead of the calculated age.

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

Sidebar

Related Questions

What I'm trying to achieve is show count of lines starting with/ending with needle
Trying to show a label only when a certain item in a combo is
I'm trying to show a UIAlertView before actually deleting a cell from a UITableView
I'm trying to show a simple countdown from 2 hours like so: $(function ()
Basically I am trying to show something like Viewing PageNumber of TotalNumberOfPages in each
I'm trying to count the number of clients associated with each health clinic, and
I have a database, and I'm trying to show the count of users for
Im trying to for each loop true @participants collection like below: - (1..@participants.count).each do
I am trying to build a report in Report Builder 3.0 which will populate
I am trying to show into article#index how many comments where on each articles.

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.