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

The Archive Base Latest Questions

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

(Also posted here .) So I have two tables, one is invalid table and

  • 0

(Also posted here.)

So I have two tables, one is invalid table and the other is valid table.

valid table:

id
status
date

invalid table:

id
status
date

I have to produce a report with this output:

date       on-time  late  total  valid  invalid1  invalid2  total  rate
---------  -------  ----  -----  -----  --------  --------  -----  ----
9/10/2011  4        10    14     3      3         3         6   
  • date: common fields on the 2 tables, field to group by, how many records on that day has
  • on-time: count of all the id on the valid table
  • late: count of all the records(id) on the invalid table
  • total: total of on-time and late
  • valid: count of id on the valid table with the “valid” status
  • invalid1: count of id on the invalid table with “invalid1” status
  • invalid2: count of id on the invalid table with “invalid2” status
  • total: total of valid, invalid1, invalid2
  • rate: average of totals

It’s basically multiple queries with different table. How can I achieve it?

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

    Someting like this?

    SELECT
        *,
        (result.total + result._total) / 2 AS rate
    FROM (
        SELECT
            date,
            SUM(CASE WHEN data.valid = 1 THEN 1 ELSE 0 END) AS ontime,
            SUM(CASE WHEN data.valid = 0 THEN 1 ELSE 0 END) AS late,
            COUNT(*) AS total,
            SUM(CASE WHEN data.valid = 1 AND data.status = 'valid' THEN 1 ELSE 0 END) AS valid,
            SUM(CASE WHEN data.valid = 0 AND data.status = 'invalid1' THEN 1 ELSE 0 END) AS invalid1,
            SUM(CASE WHEN data.valid = 0 AND data.status = 'invalid2' THEN 1 ELSE 0 END) AS invalid2,
            SUM(CASE WHEN data.status IN ('valid', 'invalid', 'invalid2') THEN 1 ELSE 0 END) AS _total
    
        FROM (
            SELECT
                date,
                status,
                valid = 1
            FROM
                Valid
            UNION ALL
            SELECT
                date,
                status,
                valid = 0
            FROM
                InValid ) AS data
        GROUP BY
            date) AS result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, one for articles/polls, and one for the votes on these
[I have posted this at the Django users | Google Groups also.] Using the
I got a great response the last time I posted here. I have the
I have seen this question posted here, but always, the answer is that the
In relation to the topic posted here: sending more than one variable with .load
This may have been posted here somewhere but I can't find it. I am
here are my two charts and my query. Obviously you do see that some
We have a simple Table per Type Entity Framework 4.0 model :- ALl classes
Forgive me if I could have any sort of fundamental error here. I'd imagine
Here's my problem. I have a middleware web service used by several web clients.

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.