Skip to content

AVG() does not work #6

Closed
Closed

Description

@agershun

I far as I know, to calculate AVG I need to keep one or two additional numbers in group:

SUM() and COUNT() - more precise approach, requires two variables

or

AVG() and COUNT() - less precise, but requires only one additional variable

I am not still sure, which approach to use.

Activity

  1. added this to the milestone on Nov 10, 2014
  2. self-assigned this
    on Nov 10, 2014
  3. IPWright83 commented on Dec 18, 2014

    @IPWright83

    If I understand correctly you're trying to decide whether to record the SUM and COUNT for the entire process and calculate the AVG at the end, or whether to calculate the AVG as you go along and add on an additional value at a time?

    If I've understood correctly I'd suggest going for the first approach, I think accuracy in functions is more important than speed. I should note that I came here hoping to use the function, so would be great to get fixed :)

  4. agershun commented on Dec 18, 2014

    @agershun
    MemberAuthor

    Thank you! I agree with you: it is better to keep SUM and COUNT, and then calculate AVG
    But, this is one point: in the future I want to add SELECT on streams (for Alacon - console file conversion utility), so probably to keep all three fields.

  5. IPWright83 commented on Dec 18, 2014

    @IPWright83

    I don't know much about the console utility (and I'll probably never need to use it). I'd suggest 3 options for you:

    • You could take the YAGNI approach and defer worrying about that until you implement that feature later on.
    • Use all 3 of your fields (I imagine that hits performance marginally?)
    • Add a flag into AVG so you call AVG(field, mode) to indicate what the other mode does. I guess this deviates from SQL the most so may be the worst case.
  6. agershun commented on Dec 18, 2014

    @agershun
    MemberAuthor

    I like YAGNI... and already spend two weeks in rewriting Alasql to make it fromsync to async - it was too difficult!

    I want implement in the next version functions in ORDER BY and GROUP BY clauses + aggregators in HAVING. So, algorithm can be the following:
    a) I will create all three fields for AVG at GROUPI BY function (like AVG$$SUM and AVG$$COUNT)
    b) create function fields for ORDER BY (like ORDER BY LCASE(field))
    c) create aggregator functions for HAVING (like HAVING COUNT(*) > 2)
    d) process HAVING and ORDER BY functions
    e) clear all unnecessary field (all fields except columns from SELECT clause)

    Ok, I will done this on the first week of January.

    Thank you for ideas!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions