Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: SQL Database Table to Perl Script

by roboticus (Chancellor)
on Oct 05, 2012 at 15:11 UTC ( #997494=note: print w/replies, xml ) Need Help??


in reply to Re^2: SQL Database Table to Perl Script
in thread SQL Database Table to Perl Script

prithviraj:

You'll want something like:

-- compute the totals for each account: select AccNum, sum(DB_amt) ttl_DB_amt, sum(CR_amt) ttl_CR_amt from ( -- transform the table from (accnum, type, amount) into -- (accnum, cr_amt, db_amt) select accnum, case when type='Credit' then Amount else 0 end CR_amt, case when type='Debit' then Amount else 0 end DB_amt from YOUR_TABLE_NAME where CHOOSE_WHICH_ACCOUNT(S)_YOU_WANT ) group by AccNum

The inner select converts your table into a simpler view of account number, credit amount and debit amount. The outer select generates the totals for the simple view.

Update: For your other questions, simply make the appropriate view transformations and accumulate the totals as above.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://997494]
help
Chatterbox?
stevieb has a significant craving to hear "My guitar gently weeps"...
[Corion]: stonecolddevin: I think Jack White is highly regarded, but ...
[Corion]: ... I'm not really knowledgeable about good guitar players
[stonecolddevin]: I've been on a Stevie Ray Vaughan kick lately: https://www. youtube.com/watch? v=wVjdMLAMbM0
[stonecolddevin]: Corion I haven't heard much of his work to be honest.
[erix]: here is a nice cover, stevieb
[planetscape]: hello, Corion
[Corion]: Hi planetscape!
[stevieb]: Corion I like the groundbreaking ones (guitar players). I have the ability to pick up on sounds that are groundbreaking or specific to a person, thanks to my years of doing recording/mixing/ sampling (hip-hop mind you, but years of it...
[stevieb]: ...has honed in my skills of recognizing sound

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (9)
As of 2017-06-22 21:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (531 votes). Check out past polls.