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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:35:02+00:00 2026-06-05T22:35:02+00:00

I have one intresting requirement to achieve. could you please help? Please find the

  • 0

I have one intresting requirement to achieve. could you please help?
Please find the below tables

**CheckingAccountTable (Assume Table Name – CAT )

AccountNo  TransactionId    BalanceID       Balance1
123           080              103             $30
123           081              103              $20
123           082              103              $10
123           083              62              $0
123           084              63              $0  
123           085              64              $0
123           086              65              $0
123           087              66              $0  
124           090              103             $3
124           091              103             $2
124           092              103             $1
124           093              72              $0
124           094              73              $0  
124           095              74              $0
124           096              75              $0
124           097              76              $0

SavingsAccountTable (Assume Table Name – SAT)

BalanceID    Balance2
103                    $0
62                    $15
63                    $12  
64                    $20
65                    $0
66                    $0
72                    $11
73                    $0  
74                    $0
75                    $0
76                    $0

RESULT SHOULD LOOKS LIKE

AccountNo  Count(TransactionId)  Sum(Balance1+Balance2)
123            6                   107
124            4                   17  

Ok, Here, CAT is the main table and SAT is the sub table to return the balance
I want to find out count of transactionID’s and Sum(Balance1 + Balance 2)

Conditions. If the Balance1 OR Balance 2 is 0, I can’t take transactionID into count

Am not able to acheive it by doing below

SELECT  T.AccountNo,Count(T.TransactionId),
                SUM(T.Balance1 + T.Balance2) 'Stressdays'
        FROM 
                (
                    SELECT  CAT.AccountNo,CAT.Balance1,CAT.BalanceID,CAT,TransactionId  
                            ,CASE   WHEN SAT.BalanceID= 103 THEN
                                        0
                                    ELSE
                                        SAT.Balance2
                                    END AS 'Balance2'
                    FROM    CAT
                            INNER   JOIN  SAT ON CAT.BalanceID = SAT.BalanceID
                            WHERE   CAT.Balance1 <> 0
                            AND     SAT.Balance2 <> 0
                )T
        GROUP BY T.AccountNo
  • 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-05T22:35:04+00:00Added an answer on June 5, 2026 at 10:35 pm

    Try the following:

    SELECT  CAT.AccountNo, 
            SUM(CASE WHEN CAT.Balance1 <> 0 OR ISNULL(SAT.Balance2,0) <> 0 THEN 1 ELSE 0 END) CountTransactionId,
            SUM(CASE WHEN CAT.Balance1 <> 0 OR ISNULL(SAT.Balance2,0) <> 0 THEN CAT.Balance1+SAT.Balance2 ELSE 0 END) SumBalance1Balance2
    FROM CAT
    LEFT JOIN SAT
    ON CAT.BalanceId = SAT.BalanceId 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a several (MySQL) tables. The interesting one is the CampaignRegion which stores
Interesting one here. I have an ASP.NET 1.1 project that contains a web service
Here is an interesting one... I have an application I am writing for devices
Alright, this one's interesting. I have a solution, but I don't like it. The
have one time consuming step that flattens a bunch of files. basically i'd like
I have one XML request which I need to modify (to XML) and then
I have one user (only one, all the others are fine) trying to update
I have one repo hosted at https://github.com/aikiframework/json . On my local copy, I added
I have one drop down list in my page, which contains two options. What
I have one problem with parsing *.docx document with OpenXML (C#). So, here's my

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.