Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SUM and COUNT

Posted on 2011-03-02
2
Medium Priority
?
329 Views
Last Modified: 2012-05-11
Hi everyone!!!

What is the query to perform a SUM and COUNT in Table A where in Table B there is a column of true and false that will be the condition for the SUM and COUNT function?

Table A has the column name "numbers".  Table B has a column name "flag"  of true and false.  Both tables share the same unique ID of course.

So my goal is to get the SUM and COUNT of the column "numbers" in tableA if FLAG = true in TableB and  if FLAG = false in TableB.

I need the two SUM and COUNT values.

Thanks in advance.
0
Comment
Question by:m3mdicl
2 Comments
 
LVL 32

Accepted Solution

by:
Ephraim Wangoya earned 2000 total points
ID: 35021721

select  flag, SUM(numbers) Summation, Count(numbers) Number
from table1
inner join table2 on table2.id = table1.id
group by flag
0
 

Author Comment

by:m3mdicl
ID: 35021836
thanks mate. works like a charm.
0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question