我想在SELECT子句中执行划分。当我加入一些表并使用聚合函数时,我通常将零值或零值作为分隔符。至于现在我只想出了这种避免零和空值除法的方法。
@H_404_1@(CASE(COALESCE(COUNT(column_name),1)) WHEN 0 THEN 1
ELSE (COALESCE(COUNT(column_name),1)) END)
我想知道有没有更好的方法呢?
由于count()不返回NULL(与其他聚合函数不同),您只需要捕获0个情况(这是唯一有问题的情况):
@H_404_1@CASE count(column_name)
WHEN 0 THEN 1
ELSE count(column_name)
END
Quoting the manual about aggregate functions:
It should be noted that except for
count
,these functions return a null value when no rows are selected.