> For the complete documentation index, see [llms.txt](https://docs.daita.ch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.daita.ch/usage/relational/functions/conditional/case-when.md).

# CASE WHEN

```typescript
const stats = await client.select({
   select: {
       height: caseWhen(case => case
          .when(greaterThan(field(Moutain, 'height'), 2000), 'Tier A')
          .when(greaterThan(field(Mountain, 'height'), 1000), 'Tier B')
          .else('Tier C'),
       name: field(Mountain, 'name'),
   }
   from: table(Mountain),
});
// sql: SELECT 
//         CASE WHEN "Mountain"."height" > 2000 THEN 'Tier A' 
//              WHEN "Mountain"."height" > 1000 THEN 'Tier B' 
//              ELSE 'Tier C' END, 
//         "Mountain"."name"
//      FROM "Mountain"
//
// const stats: { height: number, name: string }[]
```
