On 2016-05-09 4:24 AM, Cecil Westerhof wrote:
> I need to have a CEIL function in SQLite. This is the way I implemented it:
> WITH percentage AS (
>      SELECT date
>      ,           100.0 * rank / outOf         AS percentage
>      ,      CAST(100.0 * rank / outOf AS int) AS castedPercentage
>      FROM ranking
> )
> SELECT date
> ,      (CASE WHEN percentage = castedPercentage
>             THEN castedPercentage
>             ELSE castedPercentage + 1
>         END) AS percentage
> FROM percentage
>
> Is this a good way, or is there a better way?

The Ceiling function is not that simple, unless you know that your rank and 
outOf are always non-negative numbers.  If they might be negative, you would -1 
rather than +1 when the result is negative. -- Darren Duncan

Reply via email to