(1)
SELECT claimno,
SUM(
CASE
WHEN p2.lbttosubj='O'
THEN p1.judgeidt--为数字类型
ELSE 0
END) AS judgeidttriloss
FROM ods.t_idtlbts p1,
ods.t_lbt p2
WHERE p1.lbtcode=p2.lbtcode and p1.isclaimLbt='N'
gROUP BY claimno
---这样会报错“DB2 SQL0802N错误(发生算术溢出或其他算术异常)”
(2)
bigint作用:
没加bigint函数时,数据类型为整形,4个字节32bit,最长10位数字,改为bigint后,变为8个字节64bit,自然不会溢出了。
SELECT claimno,
SUM(
CASE
WHEN p2.lbttosubj='O'
THEN bigint( p1.judgeidt)
ELSE 0
END) AS judgeidttriloss
FROM ods.t_idtlbts p1,
ods.t_lbt p2
WHERE p1.lbtcode=p2.lbtcode and p1.isclaimLbt='N'
gROUP BY claimno
--这样虽然不会报溢错误,但是我的数据就不精确了,因为p1.judgeidt)后面有小数,
(3)
SELECT claimno,
SUM(
CASE
WHEN p2.lbttosubj='O'
THEN trunc(p1.judgeidt,3) ---trunc(x[,y])返回x截为y位小数的结果值
ELSE 0
END) AS judgeidttriloss
FROM ods.t_idtlbts p1,
ods.t_lbt p2
WHERE p1.lbtcode=p2.lbtcode and p1.isclaimLbt='N'
gROUP BY claimno