We help IT Professionals succeed at work.
Get Started

Gathering summary data based on two groupings

Last Modified: 2012-05-12
I am attempting to pull some logging information into a summary format.
The main fields I'm reading are the entry date, and the IP address.  I'm attempting to collect totals for the connect time.
Unfortunately, the data isn't exactly in order, so that presents my challenge.

I want to be able to insert a record in my database for each date that each IP occurs.

8/1/2011  60
8/1/2011 180
8/1/2011  60
8/2/2011  240
8/2/2011  100
8/2/2011  75

So based on the above data, I would want to have only 2 rows inserted for 8/1/2011:
  8/1/2011  120 (total of each entry of value 60)
  8/1/2011  180
but 3 rows entered for 8/2/11:
  8/2/2011  240
  8/2/2011  100
  8/2/2011  75

I've tried looping through the records but I'm having trouble catching when the date changes and/or the ip changes.  Granted, there may be times when both change as well.

I'd love sample code, but I think my biggest obstacle is the logic required...
Watch Question
Most Valuable Expert 2012
Top Expert 2014
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE