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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:08:19+00:00 2026-05-28T05:08:19+00:00

I have a table such as this ID | cid |lightness | darkness |

  • 0

I have a table such as this

ID    | cid   |lightness    | darkness     | color
------|-------|-------------|--------------|---------
1     | 5     |10           | 20           | green
2     | 5     |10           | 08           | green
3     | 5     |10           | 10           | green
4     | 5     |20           | 05           | green
5     | 8     |10           | 20           | red
6     | 8     |10           | 16           | red
7     | 8     |33           | 20           | red
8     | 5     |10           | 10           | green

I want to find out the following:

  • Count of records where color has lightness 10
  • Count of records where color has darkness 20

So the output should be

Color    | lightness   | darkness   | Total
---------|-------------|------------|---------
green    | 4           | 1          | 5
red      | 2           | 2          | 4
Total    | 6           | 3          | 9

I’ve tried the query below but it doesn’t bring the correct results.

Select color, sum(lightness), sum(darkness)
from colortable
where cid in (5,8)
and (lightness = 10 or darkness = 20)
Group by color;
  • 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-28T05:08:20+00:00Added an answer on May 28, 2026 at 5:08 am

    Save the following SQL as a new query, qryBaseCounts:

    SELECT
        sub.color,
        sub.light_10,
        sub.dark_20,
        light_10+dark_20 AS light_plus_dark
    FROM [
            SELECT
                color,
                Sum(IIf(lightness=10,1,0)) AS light_10,
                Sum(IIf(darkness=20,1,0)) AS dark_20
            FROM colortable
            WHERE
                cid In (5,8)
                AND (lightness=10
                OR darkness=20)
            GROUP BY color
        ]. AS sub;
    

    Then you can use qryBaseCounts in a UNION query:

    SELECT
        q1.color,
        q1.light_10 AS lightness,
        q1.dark_20 AS darkness,
        q1.light_plus_dark AS [Total]
    FROM qryBaseCounts AS q1
    UNION ALL
    SELECT
        "Total",
        Sum(q2.light_10)
        Sum(q2.dark_20)
        Sum(q2.light_plus_dark)
    FROM qryBaseCounts AS q2;
    

    This is the Access 2007 output from that second query using your sample data for colortable:

    color lightness darkness Total
    green         4        1     5
    red           2        2     4
    Total         6        3     9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say you have a table schema such as this: friends(friendship_id, uid1, uid2, are_friends) .
I have a table with such structure: uid sid all integers. This table simulates
I have a table such as this <table class=headerTable id=headerTable> <tbody> <tr class=hh> <td>test1</td>
I have such this table: position title --------------------------- 1 t1 2 t1 3 t2
I have a table with data such as this: <table> <tr onclick=window.location='download.php?id=1'> <td>Program 1<br/>Short
I have such table (below). I want to get someone's detail information if someones
I have a table such as the following: mafiadb:{Etzli:{alive:50,mafia:60,vigilante:3,doctor:4,citizen:78,police:40},Charneus:{alive:29,mafia:42,vigilante:6,doctor:14,citizen:53,police:33}} There are more nested tables,
I have table with 50 entries (users with such details like Name Surname Location
Lets say I have a table with columns such as: ID Name City State
i have a table with the columns such id, tid, companyid, ttype etc.. the

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.