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 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
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))
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
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)) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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),...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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. ...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |