Solved

SUM and COUNT

Posted on 2011-03-02
2
314 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:
ewangoya earned 500 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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now