Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combine records and sum

Status
Not open for further replies.

enniest

Technical User
Joined
May 17, 2006
Messages
3
Location
EE
Hello,

I'm middle of building a combination functions, the purpose of functions is to sums chargingid rows duration values.

db query results:
chargid, starttime, duration,
2223, 0610111111, 00005
2223, 0610111112, 00006
2232, 0610111113, 00001

needed output result
2223, 0610111111, 00011
2232, 0610111113, 00001
 
Are you asking this from a SQL perspective, or from a perl one?

in SQL
Code:
SELECT chargid, MIN(starttime), SUM(duration) FROM YourTable GROUP BY chargid ORDER BY chargid DESC

in perl
Code:
[COLOR=green]# Learn how to add.[/color]
 
Well if you are just trying to get the sum returned from a query you can do it in MySQL like so.
Code:
SELECT SUM(duration) FROM [i]<table>[/i] WHERE chargid = 2223

M. Brooks
 
The task need to be done in perl. I got one perl script which loads a information from flat file into mysql different tables. The second script using query results to make for evey table different format output file. Yes, i know that it can be done by mysql using group by and sum needed fields. Unfortunately i dont have any right to change query, so it need to be done in perl.

 
Unfortunately i dont have any right to change query, so it need to be done in perl.
Does this mean that the 'DB query results' posted above are in fact in a flat file, not on the DB? Otherwise I can't see how you wouldn't be able to change the query.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
all query results saved to flat file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top