...

View Full Version : Replicate SQL Group by clause function in javascript



calvinjose.87
10-10-2011, 06:53 AM
Hi

I want a javascript code that replicates the function of SQL group by clause.

I tried in several ways but couldnt find the right approach. It would be of great help if someone could guide/do the code for this process.


Thanks in advance.

Calvin

Old Pedant
10-10-2011, 09:07 AM
Isn't this the same as the question you asked re consolidating data in the other thread??

calvinjose.87
10-13-2011, 09:28 AM
ya.. but that one didnt work out as expected.

When it comes to grouping with multiple columns things are getting complicated.

So if we could simulate SQL group by in JS it will be great.

Thanks in advance

Old Pedant
10-13-2011, 08:20 PM
Well, the answer is "of course."

But *HOW* to do that depends a whole lot on how you have the data represented in your JS coding.

Are you using an array of pseudo-records? Or a keyed collection?

Is each pseudo-record itself an array? Or a typed object?

And you say you want to do GROUP BY, but there's no point in doing GROUP BY even in SQL unless you specifiy some aggregate function (e.g., COUNT or MAX or SUM or ...). HOW will you specify the aggregate function in your JS coding?

Last question: Is there some reason you are NOT doing this in SQL, instead of trying to re-invent the wheel and do it in JS?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum