Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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

Reply With Quote
  #2 (permalink)  
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?
Reply With Quote
  #3 (permalink)  
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.

Reply With Quote
  #4 (permalink)  
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.

Reply With Quote
  #5 (permalink)  
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.
Reply With Quote
  #6 (permalink)  
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:12 PM.


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