473,508 Members | 4,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL - Total results

I'm trying to construct a simple query (Hah! then why can't I figure it out
if it's so simple?) that totals the results where the drug test results are
True, negative being treated like any other result. However, instead of
giving only the count of the True results for each result, I'm getting the
count of the tests, regardless of result: a person taking three drug tests,
all negative, will display:

offender_id off_name Neg Coc
233000 Dough, John Boy 3 3

Not

233000 Dough, John Boy 3 0
Here is my (wrong) SQL:

SELECT offender_id, off_name,
Count(drug_test.dt_negative=True) AS Neg,
Count(drug_test.dt_cocaine=True) AS Coc
FROM offender
INNER JOIN drug_test
ON offender.offender_id = drug_test.dt_off_id
GROUP BY offender.offender_id, offender.off_name
Darryl Kerkeslager
Nov 13 '05 #1
4 1431
Darryl Kerkeslager wrote:
I'm trying to construct a simple query (Hah! then why can't I figure it out
if it's so simple?) that totals the results where the drug test results are
True, negative being treated like any other result. However, instead of
giving only the count of the True results for each result, I'm getting the
count of the tests, regardless of result: a person taking three drug tests,
all negative, will display:

offender_id off_name Neg Coc
233000 Dough, John Boy 3 3

Not

233000 Dough, John Boy 3 0
Here is my (wrong) SQL:

SELECT offender_id, off_name,
Count(drug_test.dt_negative=True) AS Neg,
Count(drug_test.dt_cocaine=True) AS Coc
FROM offender
INNER JOIN drug_test
ON offender.offender_id = drug_test.dt_off_id
GROUP BY offender.offender_id, offender.off_name
Darryl Kerkeslager


Try Sum(Abs(drug_test.dt_cocaine=True))

--
This sig left intentionally blank
Nov 13 '05 #2
Yup, that did it. Thanks. Makes perfect sense in hindsight, but I'm glad I
asked, because I would have beat my head black and blue trying to come up
with that solution on my own.
Darryl Kerkeslager

"Trevor Best" <no****@besty.org.uk> wrote:
Darryl Kerkeslager wrote:
Here is my (wrong) SQL:

SELECT offender_id, off_name,
Count(drug_test.dt_negative=True) AS Neg,
Count(drug_test.dt_cocaine=True) AS Coc
FROM offender
INNER JOIN drug_test
ON offender.offender_id = drug_test.dt_off_id
GROUP BY offender.offender_id, offender.off_name


Try Sum(Abs(drug_test.dt_cocaine=True))

Nov 13 '05 #3
Darryl Kerkeslager wrote:
Yup, that did it. Thanks. Makes perfect sense in hindsight, but I'm glad I
asked, because I would have beat my head black and blue trying to come up
with that solution on my own.


You can get a bit more efficient if drug_test.dt_cocaine is a boolean
field type then:

Sum(Abs(drug_test.dt_cocaine))

or even

Abs(Sum(drug_test.dt_cocaine))
--
This sig left intentionally blank
Nov 13 '05 #4
The table actually contains eight Boolean fields, for specific drug tests,
no shows, and negative results, so the solution was used eight times:)
Darryl Kerkeslager

"Trevor Best" <no****@besty.org.uk> wrote:
Darryl Kerkeslager wrote:
Yup, that did it. Thanks. Makes perfect sense in hindsight, but I'm glad I asked, because I would have beat my head black and blue trying to come up with that solution on my own.


You can get a bit more efficient if drug_test.dt_cocaine is a boolean
field type then:

Sum(Abs(drug_test.dt_cocaine))

or even

Abs(Sum(drug_test.dt_cocaine))

Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1779
by: krystoffff | last post by:
Hi I would like to paginate the results of a query on several pages. So I use a query with a limit X offset Y to display X results on a page, ok. But for the first page, I need to run the...
5
2670
by: Nick | last post by:
Is there a (better) way to get the toal number of results from a query but still limit them with a LIMIT clause. For example, in a Google search result, it displays 1-100 of 10,000,000 results. Do...
5
5297
by: Stephen Miller | last post by:
Hi, I am trying to add a staggered running total and average to a query returning quarterly CPI data. I need to add 4 quarterly data points together to calculate a moving 12-month sum (YrCPI),...
3
1539
by: zen | last post by:
PHP Mysql limit the result to 5 I can display the 5 results using a do & while which it ok. I want to list the total or all the results without using a do or while this is so I can combine...
4
10331
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem...
5
1252
by: deercreek | last post by:
I have the following sql query listed below. I show the out put be low that. I am trying to get this query to toatl and only show the line of information with the total on it. Do you have any...
4
6352
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
2
3388
by: Jinx | last post by:
Hi All I am working on a small table of only 15 columns as below: Project Name Individual Staff Name Year of Activity Then 12 Columns for each month having time spent by each individual during...
3
2090
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. ...
2
3397
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
0
7128
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7332
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1565
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.