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

The Archive Base Latest Questions

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

I have a few issues doing a typical report style SQL that I’m hoping

  • 0

I have a few issues doing a typical report style SQL that I’m hoping someone with more experience might be able to help with.

I have the following tables

products

  • product_id
  • product_name
  • product_category

product_defects

  • product_id
  • defect_date
  • high_priority
  • med_priority
  • low_priority

calendar

  • date

And what I want is to be able to generate a report that outlines the number of high / medium / low defects associated with each product category on each day e.g – even though data may not exist in product_defect for a particular day, in which case it should be returned as 0. Example:

product_category | date | high | medium | low

1 2012-10-01 1 5 6

2 2012-10-01 2 4 3

3 2012-10-01 1 5 6

1 2012-10-02 0 0 0

2 2012-10-02 2 4 3

3 2012-10-02 1 5 6

…

What I’ve done so far is:

  • Create a lookup table called calendar which has a series of days in it going back/forward several years
  • Right joined the lookup/product_defects table to get a series of dates so missing days can be marked as 0
  • Used COALESCE and SUM to calculate totals and change any missing data to 0
  • Used MIN / MAX on the defect_date to get the exact report range

I’ve banged my head on this for a few days now, hoping someone can help.

Thank you

  • 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-17T09:01:54+00:00Added an answer on June 17, 2026 at 9:01 am

    You need to start with all combinations of products and dates, and then join in the defects:

    select p.product_category, c.date, 
           coalesce(SUM(high_priority), 0) as high_priority,
           coalesce(SUM(med_priority), 0) as med_priority,
           coalesce(SUM(low_priority), 0) as low_priority
    from product p cross join
         calendar c left outer join
         product_defects pd
         on pd.product_id = p.product_id and
            pd.date = c.date
    group by p.product_category, c.date
    order by 2, 1
    

    (Note: this is untested, so may have syntax errors.)

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

Sidebar

Related Questions

I am having a few issues in doing something that I am sure is
This might be a duplicate question as I have found a few that are
I have discovered a few issues with ListViews in Mono for Android that may
Hi i am new to hibernate technology and i have few issues. Suppose if
I have a few issues with the following php functions (part of a bigger
I have a few weird issues I need to solve. First, let me show
I have a few routing issues with my ASP.NET MVC2 website and was wondering
let me first off noting that I have absolutely no idea what I'm doing
EDIT: After fixing a few issues, the bigger issue that I am having is
I have a few user controls I made in wpf that are driven by

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.