PostgreSQL数据库中,两个integer类型数据,如何处理为百分比形式
有表 student ,其中id字段为character类型,total和complete字段为integer型
total为总任务量,complete为完成任务量,当前诉求,求出完成率,保留一位小数
操作尝试
一,直接相除 complete/total,可以看到结果为0
这里为0,因为两个字段均为integer型,会按整数相除处理。
二,使用round函数 round(complete/total, 1)
这里结果与操作一类似,只是加了小数点。因为round只是对round(complete/total, 1)中输入的原值做格式化处理,而原值com