postgresql-常用数学函数

postgresql-常用数学函数

案例

--求余 1
select 5%2 as t;
--绝对值 17.4
select abs(-17.4) as t2;
-- 大于等于最小整数 -42
select ceil(-42.8) as t3;
-- 小于等于的最大整数 42
select floor(42.3) as t4;
-- 四舍五入 44
select round(43.6) as t5;
-- 向零取整 12
select trunc(12.6) as t6;
-- 随机数
-- random()返回一个大于等于 0 小于 1 的随机数,类型为双精度浮点数。
select random() as t7;
-- 随机返回员工姓名
select 
e.first_name 
from cps.public.employees e 
order by random() ;
-- 随机返回10个员工姓名
select 
e.first_name 
from cps.public.employees e 
order by random() 
limit 10;

猜你喜欢

转载自blog.csdn.net/Java_Fly1/article/details/132644206
今日推荐