Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 0 is not an option, as that will return incorrect mean/median calculations. So what would be there? Or am I misunderstanding?

Ideally, your database system would support tagged unions, and have a strong type checker. Then, you may have a column of type 'Maybe Int'. If you want to take the median, the median function would be of type 'Agg Int Int' (or something like that), so you wouldn't be able to use this column directly as an input. Instead, you'd have to only supply rows whose values have been checked to be 'Just'.

So

    CREATE TABLE MyTable ( group TEXT, myColumn MAYBE INT )
    SELECT group, MEDIAN(myColumnValue) FROM MyTable WHERE Just MyColumnValue = myColumn GROUP BY group


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: