Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: (Complex)Data Manipulation

by NetWallah (Canon)
on Feb 28, 2005 at 01:27 UTC ( [id://434977]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to (Complex)Data Manipulation

I think what you are looking for is a AOHOH, but my preference would be to let the database (SQL) do the aggregation and grouping.

The AOHOH would be:

my @db; $db[$monthNumber]->{ProductName}{RegionName} = $Quantity; # Loop through Month.. for (0..11){ #Cycle through Months, assuming zero-based next unless my %prod = %{$db[$_]}; # Any data there ? print "Some MONTH $_ header here\n"; foreach (sort keys %prod){ my %region = %{$prod{$_}}; # $region{RegionName} now has the qty to be printed # Hopefully, you get the idea now... } }
Needless to say, the code above is untested..

    ..."I don't know what the facts are but somebody's certainly going to sit down with him and find out what he knows that they may not know, and make sure he knows what they know that he may not know, and that's a good thing. I think it's a very constructive exchange," --Donald Rumsfeld

Replies are listed 'Best First'.
Re^2: (Complex)Data Manipulation
by rupesh (Hermit) on Feb 28, 2005 at 05:21 UTC

    AOHOH was what I was looking for.
    Even though I'm done with the job, I'm benchmarking all the other algorithms that fellow monks have provided.
    Many Thanks (Again)!
    Cheers,
    Rupesh.
Re^2: (Complex)Data Manipulation
by poqui (Deacon) on Feb 28, 2005 at 13:53 UTC
    Oracle SQL-wise its pretty easy:

    select product, sum(decode(region, 'asia', quantity,0)) as "Asia", sum( decode(region, 'australia',quantity,0)) as "Australia", sum( decode(region, 'UK',quantity,0)) as "UK", sum(quantity) as "Total Imported"
    from whateverthetablenameis
    group by product

    AKA: Pivot report.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://434977]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.