我试图查找两个日期之间的小时数。
不包括 sat 和 sun 以及工作时间(上午9点至下午6点)。
我发现此类代码存在using generate_series()
功能,但遗憾的是我们的版本不支持此功能。我收到以下错误:
ERROR: function generate_series(unknown, unknown, interval) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You may need to add explicit type casts.
Character: 43
如果我获得实际的功能代码以便我可以显式创建该函数然后在我的代码中使用, 否则请让我知道替代解决方案。
SELECT count(*) - 1 AS work_hours
FROM generate_series ('receiveddateandtime'
,'queryanswereddateandtime'
, interval '1h') h
WHERE EXTRACT(ISODOW FROM h) < 6
AND h::time >= '09:00'::time
AND h::time < '18:00'::time;
表结构如下:
CREATE TABLE sc141901.fpa_daily_dump_22jan
(
queryid integer NOT NULL,
querydescription text,
creatorid integer,
creatorname text,
receiveddateandtime text,
buhorizontal text,
buhorizontaldesc text,
fpateamdl text,
projectid integer,
projectname text,
customerid integer,
customername text,
parentcustomer text,
typeofissue text,
subcategory text,
monthofcpr text,
yearofcpr integer,
amount_usd numeric(23,0),
status text,
pendingwith text,
accountingissue integer,
accountingissuecomments text,
fpaanalystid integer,
fpaanalystname text,
respondeddateandtime text,
daysforresolution integer,
workingonitdateandtime text,
coordinationwithotherteamdateandtime text,
queryanswereddateandtime text,
closeddateandtime text,
comments text,
insert_date timestamp without time zone NOT NULL DEFAULT now()
)