上云无忧 > 文档中心 > 百度数据仓库 Palo SQL语法手册 - 条件函数
百度数据仓库 Palo Doris版
百度数据仓库 Palo SQL语法手册 - 条件函数

文档简介:
PALO 支持的条件函数如下: 1.case 2.coalesce 3.if 4.ifnull 5.nullif
*此产品及展示信息均由百度智能云官方提供。免费试用 咨询热线:400-826-7010,为您提供专业的售前咨询,让您快速了解云产品,助您轻松上云! 微信咨询
  免费试用、价格特惠

PALO 支持的条件函数如下:

1.case
2.coalesce
3.if
4.ifnull
5.nullif

CASE

Description

CASE a WHEN b THEN c [WHEN d THEN e]... [ELSE f] END
  • 功能:将表达式和多个可能的值进行比较,当匹配时返回相应的结果
  • 返回类型:匹配后返回结果的类型

Example

mysql> select case tiny_column when 1 then "tiny_column=1" when 2 then "tiny_column=2"
 end from small_table limit 2; +-------------------------------------------------------
------------------------+ | CASE`tiny_column` WHEN 1 THEN 'tiny_column=1' WHEN 2 THEN
 'tiny_column=2' END | +------------------------------------------------------------------
-------------+ | tiny_column=1 | | tiny_column=2 | +----------------------------------------
---------------------------------------+ mysql> select case when tiny_column = 1 then "tiny_column=1"
 when tiny_column = 2 then "tiny_column=2" end from small_table limit 2; +-------------------------
------------------------------------------------------+ | CASE`tiny_column` WHEN 1 THEN 'tiny_column=1'
 WHEN 2 THEN 'tiny_column=2' END | +-----------------------------------------------------------------
--------------+ | tiny_column=1 | | tiny_column=2 | +------------------------------------------------
-------------------------------+

Keywords

case

COALESCE

Description

coalesce( expression,value1,value2……,valuen)
  • 功能:返回包括expression在内的所有参数中的第一个非空表达式。expression为待检测的表达式,而其后的参数个数不定。
  • 返回类型:匹配后返回结果的类型

Example

mysql> select coalesce(NULL, '1111', '0000'); +------------------------------
--+ | coalesce(NULL, '1111', '0000') | +--------------------------------+ | 1111 | +--------------------------------+

Keywords

coalesce

IF

Description

if(boolean condition, type ifTrue, type ifFalseOrNull)
  • 功能:测试一个表达式,根据结果是true还是false返回相应的结果
  • 返回类型:ifTrue表达式结果的类型

Example

mysql> select if(tiny_column = 1, "true", "false") from small_table limit 1; +---------------------
-------------------+ | if(`tiny_column` = 1, 'true', 'false') | +-------------------------------
---------+ | true | +----------------------------------------+

Keywords

if

IFNULL

Description

ifnull(expr1, expr2)
  • 功能:测试一个表达式,如果表达式是NULL,则返回第二个参数,否则返回第一个参数。
  • 返回类型:第一个参数的类型

Example

mysql> select ifnull(1,0); +--------------+ | ifnull(1, 0) | +--------------+ | 1 | +---------
-----+ mysql> select ifnull(null,10); +------------------+ | ifnull(NULL, 10) | +-----
-------------+ | 10 | +------------------+

Keywords

ifnull

NULLIF

Description

nullif(expr1, expr2)
  • 功能:如果两个参数相等,则返回NULL。否则返回第一个参数的值。它和以下的CASE WHEN效果一样。
  • 返回类型:expr1的类型或者NULL
CASE WHEN expr1 = expr2 THEN NULL ELSE expr1 END

Example

mysql> select nullif(1,1); +--------------+ | nullif(1, 1) | +--------------+ | NULL | +----
----------+ mysql> select nullif(1,0); +--------------+ | nullif(1, 0) | +--------------+ | 1 | +--------------+

Keywords

nullif

相似文档
  • PALO 支持的时间类型 包括 DATE 和 DATETIME 两种类型。 DATE 类型格式为:"2020-10-10" DATETIME 类型格式为:"2020-10-10 11:10:06" PALO 支持的日期和时间函数如下:
  • PALO 的格式转换函数如下: 1.aes_encrypt 2.aes_decrypt 3.to_base64 4.from_base64 5.md5,md5sum AES_ENCRYPT Description: aes_encrypt(string str, string key) 功能:使用key作为密钥,给str加密,返回加密后的结果。
  • 窗口函数是一类特殊的内置函数。和聚合函数类似,窗口函数也是对于多个输入行做计算得到一个数据值。不同的是,窗口函数是在一个特定的窗口内对输入数据做处理,而不是按照 group by 来分组计算。
  • PALO 支持以下类型转换函数: CAST Description: cast(expr as type) 功能:转换函数通常会和其他函数一同使用,显示的将expression转换成指定的参数类型。PALO 对于函数的参数类型有严格的数据类型定义。例如 PALO 不会自动将 bigtint 转换成 int 类型,或者其余可能会损失精度或者产生溢出的转换。
  • 聚合函数的行为是将多行的结果聚合成一行。 PALO 支持以下聚合函数: 1.avg 2.count 3.approx_count_distinct 4.max 5.min 6.sum 7.group_concat 8.variance_samp 9.variance_pop 10.percentile_approx 11.topn
官方微信
联系客服
400-826-7010
7x24小时客服热线
分享
  • QQ好友
  • QQ空间
  • 微信
  • 微博
返回顶部