SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE "operator_activity" ( "id" SERIAL8 NOT NULL, "type" VARCHAR(50) NOT NULL, "created_date_time" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6), "operator_id" INT8 NOT NULL, PRIMARY KEY (id) ); SELECT DISTINCT oa.operator_id, ( EXTRACT( EPOCH FROM ( oaMax.created_date_time - oaMin.created_date_time ) )/ 60 ) AS minutes FROM "operator_activity" AS oa JOIN ( SELECT operator_id, created_date_time FROM "operator_activity" ORDER BY id ASC LIMIT 1 ) oaMin ON oaMin.operator_id = oa.operator_id JOIN ( SELECT operator_id, created_date_time FROM "operator_activity" ORDER BY id DESC LIMIT 1 ) oaMax ON oaMax.operator_id = oa.operator_id WHERE oa.type IN('OPEN') AND extract( year from oa.created_date_time ) = 2022 AND extract( month from oa.created_date_time ) = 4
Stuck with a problem? Got Error? Ask ChatGPT!
Copy Clear