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 a database with two tables ( Table1 and Table2 ). They both
I have two tables, let's call them table1 and table2 . They both have
i have in the database typical tables like user, usergroup, and they have relations.
I have 2 tables; they have a many-to-many relationship. One is called Blog the
i have two tables: Authority , Permission they have many to many relationship class
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
I have two tables, and they are using different collations. It is not allowed
I have some tables that represent various types. They usually just consist of an
I have 3 database tables, all of them have the same 5 columns. They
I have a database with two main tables notes and labels . They have

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.