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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:26:24+00:00 2026-06-10T10:26:24+00:00

I have a table that has the following data (shortened for this example): C1

  • 0

I have a table that has the following data (shortened for this example):

    C1    C2    C3    C4
=========================
1   0     1     1     0
2   1     1     0     1
3   1     0     1     1
4   1     1     1     1
5   0     0     1     1
6   0     0     0     1

I want to create a create a query that gives me the following result:

    C3    C4
=============
C1   2     3 
C2   2     2

That is, the combination of those four columns when:

C1 = 1 & C3 = 1
C1 = 1 & C4 = 1
C2 = 1 & C3 = 1
C2 = 1 & C4 = 1

I’ve been able to get make some progress, but not ultimately what I want. I’ve managed to get this far: http://sqlfiddle.com/#!3/7d3d4/2/0

but I can’t figure out how to get my query to format like my desired output above. I was going to try to use a PIVOT table, but quickly abandoned that idea because it seemed to get extremely convoluted once I needed to add a 2nd PIVOT statement (and I’d end up having to add more as my example above is a really basic example of the number of columns I need to perform this on).

What am I missing?

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-10T10:26:25+00:00Added an answer on June 10, 2026 at 10:26 am

    try this:

    SELECT 'C1',SUM(CASE WHEN C1=1 AND C3=1 THEN 1 END)AS C3,
                SUM(CASE WHEN C1=1 AND C4=1 THEN 1 END)AS C4
    FROM T1
    UNION ALL
    SELECT 'C2',SUM(CASE WHEN C2=1 AND C3=1 THEN 1 END)AS C3,
                SUM(CASE WHEN C2=1 AND C4=1 THEN 1 END)AS C4
    FROM T1
    

    SQL Fiddle Demo

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

Sidebar

Related Questions

I have a mongo table that has statistical data like the following.... course_id status
I have a table that has the following format for the data. All I
I have a data table that has the following columns: id (string), date (date),
i have a table that has following column Type -------- type 1 type 2
I have a table that has multiple rows with the following fields: PersonName SongName
I have a MSSQL table stores that has the following columns in a table:
I have a SQL database that has the following table: Table: PhoneRecords -------------- ID(identity
I have a table that has the following columns Id ForeignKeyId AttributeName AttributeValue Created
Assume I have a table that has the following structure: ================= | Id |
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+

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.