Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: SQL Database Table to Perl Script

by james2vegas (Chaplain)
on Oct 05, 2012 at 05:23 UTC ( #997382=note: print w/replies, xml ) Need Help??


in reply to SQL Database Table to Perl Script

Just include in your SELECT and GROUP BY your additional fields.

Replies are listed 'Best First'.
Re^2: SQL Database Table to Perl Script
by prithviraj (Novice) on Oct 05, 2012 at 07:12 UTC
    What are the additional fields Sir? Please help with the full SQL query.
      I do not know the additional fields (how would I). They would be in your schema.

      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://997382]
help
Chatterbox?
[PriNet]: quick question... anyone know how to remove all the existing keys in a %hash ? i've tried several options, but when i re-use the hash, some of the "upper" keys that i don't re-use stick and i can't get them to "remove"
[atcroft]: PriNet: %hash = ();? or foreach my $k ( keys %hash ) { delete $hash{$k}; }?

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2017-06-28 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (619 votes). Check out past polls.