Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2005, 01:06 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Running Total

I have two tables with Data in them

DFMMR:
ID Display Sdate Edate
1 April 2004 4/1/2004 4/30/2004
and so on

Member_dates:
id ent_date ext_date
1 4/2/2004
2 4/2/2004
3 1/2/2004 2/2/2004


Here is my Code so far:

Select
dfmmr.display as Month,

(Select count(*) from member_dates MB where MB.ent_date between
dfmmr.sdate and dfmmr.edate) as Addtions,

(Select count(*) from member_dates MB where MB.ext_date between
dfmmr.sdate and dfmmr.edate) as Deletions

from dfmmr where dfmmr.active = '1'
group by sdate,edate,display

The output Looks like this:
Month Addtions Deletions
April 2004 12 14
May 2004 9 2

I need to keep a running total like this
and like this
Month Beg Addtions Deletions Ending
April 2004 0 12 2 10
May 2004 10 9 2 17

Please Help

 
Old March 9th, 2005, 02:28 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

How does this work, you are not joining the tables anywhere. Is this the complete SQL?
 
Old March 9th, 2005, 02:31 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am just using the Subquerys to get the data.

 
Old March 9th, 2005, 02:32 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It goes through the DFMMR table which has each month in it. Then Displays the Counts for Addtions and Deletions for each month from the mamber_date table.

 
Old March 9th, 2005, 03:14 PM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

I am a little confused to what your data represents. Are the tables a 1 to 1 relationship. How are SDate, EDate different from ent_date, ext_date.
 
Old March 9th, 2005, 03:28 PM
Registered User
 
Join Date: Mar 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sdate is like the Start Date of each month like 3/1/04 and edate is the last date like 3/31/04

That is just by bases for the query to Member_dates which ent_date is any date and well as ext_date is date. I need the totals for each month so if there is 4 member with ent_date of
id ent_date ext_date
1 3/2/04
2 3/12/04 3/25/04
3 3/12/04
4 3/20/04

Then it would show up the the parameters of the sdate and e date of 3/1/04 to 3/31/04

Which would equal 4
But person 2 also exited so it is
Month Add Del
3/2004 4 1

Do you see now? There really is no relationship as much as just one table hold search critera for another table to search by which are each months dates start and ending.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate a running total Neal XSLT 3 March 22nd, 2007 11:16 AM
Crystal reports running total prathap Other Programming Languages 0 October 17th, 2006 04:00 AM
Using Running total in crystal reports prathap BOOK: Professional Crystal Reports for VS.NET 0 October 17th, 2006 02:37 AM
Running Total Fields edramail Crystal Reports 0 May 17th, 2004 09:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.