简体   繁体   中英

Can we do customized COALESCE() in BigQuery?

I've been using COALESCE since the first time I used BQ. So basically it looks for a non-NULL value within the bracket.

Is there any way for us to customize it? For example I have two fields that has values either ACTIVE or INACTIVE. I'd like to know whether one of the value from those fields is ACTIVE.

For example:

  • COALESCE('Inactive', 'Active') returns 'Active'
  • COALESCE('Active', 'Inactive') returns 'Active'
  • COALESCE('Inactive', 'Inactive') returns 'Inactive'

Is it possible to use any function for this purpose? Thank you

Use below instead

SELECT 
  LEAST('Inactive', 'Active'), 
  LEAST('Active', 'Inactive'),
  LEAST('Inactive', 'Inactive')    

with output

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM