我需要获取整数的最后两位数.放在表格中的每个元素都是全年,即.YYYY我只想要最后两位数字,以便显示所有字段
YEAR
----
09
00
89
Run Code Online (Sandbox Code Playgroud)
最初的领域是什么
YEAR
----
2009
2000
1989
Run Code Online (Sandbox Code Playgroud)
编辑:我得到投诉说,
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
当我尝试
select right(cast(year as char),2) from subjects;
wil*_*ser 11
Postgres从C借用(或继承)了模数运算符:
SET search_path='tmp';
CREATE TABLE lutser ( year integer);
INSERT INTO lutser (year)
SELECT generate_series(1991,2012)
;
SELECT year
, year / 100 as c2
, year % 100 AS y2
FROM lutser
;
Run Code Online (Sandbox Code Playgroud)
结果:
CREATE TABLE
INSERT 0 22
year | c2 | y2
------+----+----
1991 | 19 | 91
1992 | 19 | 92
1993 | 19 | 93
1994 | 19 | 94
1995 | 19 | 95
1996 | 19 | 96
1997 | 19 | 97
1998 | 19 | 98
1999 | 19 | 99
2000 | 20 | 0
2001 | 20 | 1
2002 | 20 | 2
2003 | 20 | 3
2004 | 20 | 4
2005 | 20 | 5
2006 | 20 | 6
2007 | 20 | 7
2008 | 20 | 8
2009 | 20 | 9
2010 | 20 | 10
2011 | 20 | 11
2012 | 20 | 12
(22 rows)
Run Code Online (Sandbox Code Playgroud)