Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
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 AI support!

Copy Clear