Skip to content

Get Min & Max date from table? #425

Closed

Description

@thierrygervais

Hello,

Is it possible to get the Min or Max date from a table?

alasql("CREATE TABLE TestDates (StartDate DATE, EndDate DATE) ");
alasql("INSERT INTO TestDates VALUES('2015.10.23', '2015.11.24') ");
alasql("INSERT INTO TestDates VALUES('2015.11.23', '2015.12.24') ");
alasql("INSERT INTO TestDates VALUES('2015.12.23', '2015.13.24') ");

alasql("Select MIN(StartDate) FROM TestDates ");
alasql("Select MAX(StartDate) FROM TestDates ");

It returns undifined

The only way I managed to do it is to use a timestamp.

Thank

Thierry

Activity

  1. mathiasrw commented on Sep 23, 2015

    @mathiasrw
    Member

    As I recall the min and max only works on numbers.

    Its a good point supporting dates.

    While we do that you can check out if you can use something like

    select startdate from testdates order by startdate DESC limit 1
    select startdate from testdates order by startdate ASC limit 1
    
  2. self-assigned this
    on Sep 23, 2015
  3. thierrygervais commented on Sep 24, 2015

    @thierrygervais
    Author

    Thank Mathias,

    That's a good trick for now.

    Best regards

    Thierry

  4. added this to the SQL compliance milestone on Jan 22, 2016
  5. removed their assignment
    on Nov 20, 2016
  6. chryschabert commented on May 27, 2019

    @chryschabert

    Any plans to fix this ? Work arounds are ok, but it'd be nice to support MIN/MAX for date types as well.

  7. mathiasrw commented on Sep 5, 2019

    @mathiasrw
    Member

    Anyone are free to look into this. I have a feeling its not a hard fix.

  8. chamakura commented on Mar 17, 2020

    @chamakura

    Is this still an issue? The below is successfully passing the tests:

    var res = [];
    res.push(alasql('create table one (dateField DATE)'));
    res.push(alasql('insert into one values (\'2015.10.23\'), (\'2015.11.23\'), (\'2015.12.23\')'));
    res.push(alasql('select MIN(dateField) min_d from one'));
    res.push(alasql('select MAX(dateField) max_d from one'));
    assert.deepEqual(res, [1, 3, [{min_d: '2015.10.23'}], [{max_d: '2015.12.23'}]]);
    
  9. chryschabert commented on Mar 18, 2020

    @chryschabert

    It was fixed in January this year according to release notes, so I guess it is no longer an issue.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions