Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9196239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:48:28+00:00 2026-06-17T21:48:28+00:00

In PostgreSQL I have a table CREATE TABLE cubenotification.newnotification ( idnewnotification serial NOT NULL,

  • 0

In PostgreSQL I have a table

CREATE TABLE cubenotification.newnotification
(
  idnewnotification serial NOT NULL,
  contratto text,
  idlocation numeric,
  typology text,
  idpost text,
  iduser text,
  idobject text,
  idwhere text,
  status text DEFAULT 'valid'::text,
  data_crea timestamp with time zone DEFAULT now(),
  username text,
  usersocial text,
  url text,
  apikey text,
  CONSTRAINT newnotification_pkey PRIMARY KEY (idnewnotification )
)

Let’s say that typology field can be “owned_task” or “fwd_task”.
What I’d like to get from DB is the timestamp difference in seconds strictly between data_crea of the row with typology “fwd_task” and data_crea of the row with typology “owned_task” for every couple “idobject,iduser”, and I’d like to get also the EXTRACT(WEEK FROM data_crea)) as “weeks”, grouping the results by “weeks”. My problem is principally about performing the timestamp ordered difference between two rows with same idobject, same iduser and different typology.

EDIT:
Here some sample data

sample data

and sqlfiddle link http://sqlfiddle.com/#!12/6cd64/2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:48:29+00:00Added an answer on June 17, 2026 at 9:48 pm

    What you are looking for is the JOIN of two subselects:

    SELECT EXTRACT(WEEK FROM o.data_crea) AS owned_week
         , iduser, idobject
         , EXTRACT('epoch' FROM (o.data_crea - f.data_crea)) AS diff_in_sek
    FROM  (SELECT * FROM newnotification WHERE typology = 'owned_task') o
    JOIN  (SELECT * FROM newnotification WHERE typology = 'fwd_task')   f
                                                             USING (iduser, idobject)
    ORDER  BY 1,4
    

    ->sqlfiddle

    I order by week and timestamp difference. The week number is based on the week of ‘owned_task’.

    This assumes there is exactly one row for ‘owned_task’ and one for ‘fwd_task’ per (iduser, idobject), not one per week. Your specification leaves room for interpretation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables: CREATE TABLE article ( id serial NOT NULL, title text,
I have this table in postgreSQL v9.1: CREATE TABLE ad_treenodemm ( ad_tree_id numeric(10,0) NOT
I have such table: CREATE TABLE employee ( id INTEGER DEFAULT NEXTVAL('ids'::regclass) NOT NULL,
I have a table like: CREATE TABLE test( id integer not null default nextval('test_id_seq'::regclass),
I have created a table in postgresql 9 create table stillbirth(id serial primary key,
I have the following table: CREATE TABLE place ( id int8 NOT NULL DEFAULT
I have a table in Postgresql DROP TABLE xml_docs; CREATE TABLE xml_docs( id serial
When I have the following table: CREATE TABLE test ( id integer NOT NULL,
I currently have: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY,
I have the following table and sequence in my postgresql-8.4 database: CREATE TABLE complexobjectpy

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.