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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:08:24+00:00 2026-05-17T02:08:24+00:00

This is not a homework question, just something at work that’s bugging me. I’m

  • 0

This is not a homework question, just something at work that’s bugging me.

I’m trying to write a query against these tables below. The two tables, history and code are joined to the historyassignment table by the historyid and codeid columns.

Table: HistoryAssignment

| AssignmentID | HistoryID | CodeID |
|--------------|-----------|--------|
| 1            | 100       | 200    |
|--------------|-----------|--------|
| 2            | 101       | 201    |
|--------------|-----------|--------|
| 3            | 102       | 202    |
|--------------|-----------|--------|

Table: Code 

| CodeID | Desc |
|--------|------|
| 200    | ABC  |
|--------|------|
| 201    | DEF  |
|--------|------|
| 202    | GHI  |
|--------|------|

Table: History

| HistoryID | Desc | HistDate |
|-----------|------|----------|
| 100       | JKL  | 5/1/2010 |
|-----------|------|----------|
| 101       | MNO  | 7/1/2009 |
|-----------|------|----------|
| 102       | PQR  | 7/9/2010 |
|-----------|------|----------|
| 103       | STU  | 6/2/2010 |
|-----------|------|----------|
| 104       | VWX  | 5/7/2010 |
|-----------|------|----------|
| 105       | YZ   | 2/5/2010 |
|-----------|------|----------|

My goal is to get a count of total number of history IDs that are mapped in the historyassigment table and the total number of history IDs there are in the history table. The results should be grouped the month and year of the histdate column in the history table. Like below.

Year    Month   Total   Mapped
2009    7   1   1
2010    2   1   0
2010    5   2   1
2010    6   1   0
2010    7   1   1

Any assistance would be greatly appreciated.

  • 1 1 Answer
  • 1 View
  • 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-17T02:08:24+00:00Added an answer on May 17, 2026 at 2:08 am
    SELECT   YEAR(HistDate) [Year]      ,
             MONTH(HistDate) [Month]    ,
             COUNT(h.HistoryID) [Total] ,
             COUNT(DISTINCT ha.HistoryID) [Mapped]
    FROM     History h
             LEFT OUTER JOIN HistoryAssignment ha
             ON       ha.HistoryID = h.HistoryID
    GROUP BY YEAR(HistDate),
             MONTH(HistDate)
    ORDER BY YEAR(HistDate),
             MONTH(HistDate)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve this problem, its not a homework question, its just code
this one is not homework, it just the fact that i've been out of
This isn't actually a homework question per se, just a question that keeps nagging
Just want to ensure you that it is not a homework question. I am
This question is not a homework, it is just out of personal interest and
This is not homework, just a question about my code (I'm learning C++). I
Codingbat.com array question This is a simple array question, not for homework, just for
Just to clarify this is NOT a homework question as I've seen similar accusations
Please note that this is not homework and i did search before starting this
This IS NOT a Homework question! While building my current student database project I

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.