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;
本文介绍了在PostgreSQL中使用的一些常用数学函数,如求余、绝对值、四舍五入、向零取整以及生成随机数。还展示了如何利用这些函数获取随机员工姓名,包括单个和前10个随机记录。
1339

被折叠的 条评论
为什么被折叠?



