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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:20:56+00:00 2026-06-08T20:20:56+00:00

I have a results table which lists a set of values, each linking to

  • 0

I have a results table which lists a set of values, each linking to another table containing the date that result was made.

I have working SQL to get all the dates (using CASE’s) however I can only retrieve a single range of results.

    Select 
    count(CASE
    WHEN  results.test_id IN ( SELECT id 
    FROM  `test` 
    WHERE  `posted` 
    BETWEEN  '2011-07-01 00:00:00'
    AND  '2011-07-01 23:59:59') 
    THEN results.test_id
    ELSE NULL
        END) AS "1st July"          
    from `results`
    WHERE results.window_id = 2 and results.mark > 90;

I also have another SQL query which gets all the ranges but can only work for one date at a time.

SELECT
CASE
    when mark > 90 then '>90%'
    when mark > 80 then '>80%'
    when mark > 70 then '>70%'
END as mark_results,
COUNT(*) AS count

FROM (SELECT mark from results where window_id =2) as derived
GROUP BY mark_results
ORDER BY mark_results;

What I’d like is to have everything in one unified query, displaying the relevant totals for each range of results. such as below:

Result Range | 1st July | 2nd July | 3rd July | 4th July
>90%         |    0     |    0     |    0     |    1
>80%         |    1     |    2     |    1     |    1
>70%         |    4     |    5     |    5     |    4

So that the totals for each range are displayed under their date.

I assume it’s possible.

  • 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-08T20:20:59+00:00Added an answer on June 8, 2026 at 8:20 pm

    The following statement joins results and tests in the FROM clause. It then aggregates the query by the mark range, with the counts per day:

    Select (CASE when mark > 90 then '>90%'
                 when mark > 80 then '>80%'
                 when mark > 70 then '>70%'
           END) as mark_results,
         sum(case when posted BETWEEN  '2011-07-01 00:00:00' AND  '2011-07-01 23:59:59' then 1 else 0 end) as July01,
         sum(case when posted BETWEEN  '2011-07-02 00:00:00' AND  '2011-07-02 23:59:59' then 1 else 0 end) as July02,
         . . . 
    from `results` r join
         test t
         on r.test_id = t.test_id
    WHERE r.window_id = 2 and results.mark > 90
    group by (CASE when mark > 90 then '>90%'
                   when mark > 80 then '>80%'
                   when mark > 70 then '>70%'
              END)
    order by 1
    

    Just add whatever days you want to the SELECT clause.

    I should add . . . if you want all the dates, you need to put them on separate rows:

    Select date(posted) as PostedDate,
          (CASE when mark > 90 then '>90%'
                 when mark > 80 then '>80%'
                 when mark > 70 then '>70%'
           END) as mark_results,
         count(*) as cnt
         . . . 
    from `results` r join
         test t
         on r.test_id = t.test_id
    WHERE r.window_id = 2 and results.mark > 90
    group by date(posted),
             (CASE when mark > 90 then '>90%'
                   when mark > 80 then '>80%'
                   when mark > 70 then '>70%'
              END)
    order by 1, 2
    

    In fact, you might consider having a separate row for each date, with the ranges pivoted as columns.

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

Sidebar

Related Questions

I have the following loop which is giving me problems $(#divResults).append('<table>'); $.each( results.d, function(
I have a table 'results' in which the scores are stored. Its ordered by
I have a table which stores test results like this: user | score |
I have a table which is dynamically created based on the amount of results
I have two tables. One user table and one table in which results are
I have a huge data.table in R which contains the result of a experiment:
I have a table of football results: CREATE TABLE matches( season NUMBER(4), matchDate DATE,
I have a query which I run on a table TXN_DEC(id, resourceid, usersid, date,
I need to have one table in which i can set user preferences I
I have a database return result which has flatten results like below. I want

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.