473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calculating data where it exists and give '0' value where it doesn't

Hi,

I'm working on a database where I need to calculate some data that fits
certain sets of parameters, but I'd like it to give me more information
than I know how to get.

As an example, let's say I'm querying a table with the following fields:

pmt_no pmt_amt staff_id

pmt_no is unique, but isn't being used in these calculations.

I've done a query that counts the number of payments as long as the
payment is more than 50:

SELECT tbl_accounts.staff_id, Count(tbl_accounts.pmt_amt) AS no_of_payments
FROM tbl_accounts
WHERE (((tbl_accounts.pmt_amt)>=50))
GROUP BY tbl_accounts.staff_id;

This works fine, as far as it's meant to: it gives me a list of all the
people who've had any payments >=50.

However, what I'd really like is maybe to link this with another table
that contains *all* staff_ids and, if they haven't had a payment of over
50, I'd like my query to give me a '0' next to that staff id.

Is this possible or am I hoping for too much? :)

(Please do let me know if anything is unclear - I tried to think of as
simple an example as possible; my real data is very slightly more
complex, but the principle is the same!)

Thank you for reading this far. ;)

-Jen (if you care to reply by email, remove the spork)
Oct 16 '08 #1
2 1370
Jen P. wrote:
Hi,

I'm working on a database where I need to calculate some data that fits
certain sets of parameters, but I'd like it to give me more information
than I know how to get.

As an example, let's say I'm querying a table with the following fields:

pmt_no pmt_amt staff_id

pmt_no is unique, but isn't being used in these calculations.

I've done a query that counts the number of payments as long as the
payment is more than 50:

SELECT tbl_accounts.staff_id, Count(tbl_accounts.pmt_amt) AS no_of_payments
FROM tbl_accounts
WHERE (((tbl_accounts.pmt_amt)>=50))
GROUP BY tbl_accounts.staff_id;

This works fine, as far as it's meant to: it gives me a list of all the
people who've had any payments >=50.

However, what I'd really like is maybe to link this with another table
that contains *all* staff_ids and, if they haven't had a payment of over
50, I'd like my query to give me a '0' next to that staff id.

Is this possible or am I hoping for too much? :)

(Please do let me know if anything is unclear - I tried to think of as
simple an example as possible; my real data is very slightly more
complex, but the principle is the same!)

Thank you for reading this far. ;)

-Jen (if you care to reply by email, remove the spork)
In the query builder drop both tables into it. Most likely there will
be a link line between StaffID in both tables. Dbl-Click on the line
and select "All recs from EmpTable and Matching recs from TblAccounts"

Drag the StaffID from tblAccounts. If it's null, then it'd be 0.

Oct 16 '08 #2
Salad wrote:
Jen P. wrote:
<snip>
>I've done a query that counts the number of payments as long as the
payment is more than 50:

SELECT tbl_accounts.staff_id, Count(tbl_accounts.pmt_amt) AS
no_of_payments
FROM tbl_accounts
WHERE (((tbl_accounts.pmt_amt)>=50))
GROUP BY tbl_accounts.staff_id;

This works fine, as far as it's meant to: it gives me a list of all
the people who've had any payments >=50.

However, what I'd really like is maybe to link this with another table
that contains *all* staff_ids and, if they haven't had a payment of
over 50, I'd like my query to give me a '0' next to that staff id.
<snip>
In the query builder drop both tables into it. Most likely there will
be a link line between StaffID in both tables. Dbl-Click on the line
and select "All recs from EmpTable and Matching recs from TblAccounts"

Drag the StaffID from tblAccounts. If it's null, then it'd be 0.
Hurrah! Cheers for that. :) I ran into an 'Ambiguous outer join'
error, but I was able to fix that with a quick Google and help from:

<http://rogersaccessblog.blogspot.com/2008/09/ambiguous-outer-joins.html>

Many thanks for your quick and extremely helpful reply. :D

-Jen
Oct 17 '08 #3

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

Similar topics

1
by: Da-Breegster | last post by:
Hi. I'm attempting to write a roguelike (think nethack, crawl, angband, tome, adom, and yes, I suppose even rogue) in Perl and I've ran into a problem regarding the data structure for the map and...
10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
1
by: StormyTheCat | last post by:
Perhaps this is easy, but I'm new to C# am in need of some help. I need to embed a CRC value into an XML file to be able to detect when the data contained therin is corrupted. Calculating the...
3
by: Bob Day | last post by:
VS 2003, sql How do you determine the data type of a column if its value is DBNull? 1)Table: Column1 STRING non-nullable 2) Fill to a DataSet via DataAdapter 3) dim Data_Type_Is...
1
by: Anonieko | last post by:
Here are some of the approaches. 1. Transform DataGrid http://www.dotnetjohn.com/articles.aspx?articleid=36 3. Use the Export approach ...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
7
by: Arpan | last post by:
The .NET Framework 2.0 documentation states that An Object variable always holds a pointer to the data, never the data itself. Now w.r.t. the following ASP.NET code snippet, can someone please...
38
by: jdcrief | last post by:
Complier: Visual C++ 2005 Express Edition The program I wrote will compile and execute, but the output is always the same, no matter what number is entered in for the radius of the circle. ...
4
by: =?Utf-8?B?TmF2YW5lZXRoLksuTg==?= | last post by:
Say I have a class like, class Sample { public decimal first = 10; public decimal second = 20; } I have initialized it
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
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.