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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:12:39+00:00 2026-05-25T13:12:39+00:00

I have 3 tables. They have 1 to many relations table1 – mainID, Select00(bit),

  • 0

I have 3 tables. They have 1 to many relations

table1 - mainID, Select00(bit), Select01(bit)
table2 - secID, mainID
table3 - secID, Num00, Num01



SELECT  table1.mainID ,  SUM(table3.Num00) as S00, SUM(table3.Num01) as S01
FROM    table1 INNER JOIN
        table2 ON table1.mainID = table2.mainID INNER JOIN
        table3 ON table2.secID = table3.secID
GROUP BY table1.mainID HAVING table1.mainID =11

The following query works, but gives me all sums.

How do I get the SUMs based on condition? i.e

S00 = SUM(table3.Num00) if table1.Select00 = 1 (true)
S01 = SUM(table3.Num01) if table1.Select01 = 1 (true)
  • 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-25T13:12:40+00:00Added an answer on May 25, 2026 at 1:12 pm
    SELECT
        t1.mainID,
        S00 = SUM(CASE WHEN t1.Select00 = 1 THEN t3.Num00 ELSE 0 END),
        S01 = SUM(CASE WHEN t1.Select01 = 1 THEN t3.Num01 ELSE 0 END)
    FROM 
        dbo.table1 AS t1
        INNER JOIN dbo.table2 AS t2
        ON t1.mainID = t2.mainID
        INNER JOIN dbo.table3 AS t3
        ON t2.secID = t3.secID
    WHERE t1.MainID = 11
    GROUP BY table1.mainID;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, let's call them table1 and table2 . They both have
I have 3 tables. users, campaigns, links. They have one-to-many relations. User have many
I have two tables: Items and Colors. They have a many to many relation.
i have two tables Coupon and Tags they have many to many relation now
I have two tables and they highlight as expected, but I only want the
I have three tables with 5 columns each. They can grow upto 15 rows
I have two tables that have virtually identical content and very similar structure. They
I have multiple tables in a MySQL database. Lets say they look like this:
I have four tables. Three of them are tables with one key and they
I have two auditing tables: Trip_aud and Event_aud. They were created in Envers, but

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.