Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Replicate SQL Group by clause function in javascript

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,548
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    Isn't this the same as the question you asked re consolidating data in the other thread??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,548
    Thanks
    77
    Thanked 4,382 Times in 4,347 Posts
    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?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •