Sqlite - If Statement

Table of Contents

About

Most SQL database does not use the if construct but the conditional case statement to express a condition.

Example

For example where Saturday and Sunday are marked as weekend and the other days as midweek

with day as (select cast(strftime('%w', date()) as integer) as weekday)
select case
           when day.weekday == 0 then 'Weekend'
           when day.weekday == 6 then 'Weekend'
           else 'MidWeek' end as weekpart
from day

Powered by ComboStrap