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

  • SEARCH
  • Home
  • 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 3433248
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:33:02+00:00 2026-05-18T07:33:02+00:00

sorry for the title but I’m not sure how I should call it. I’m

  • 0

sorry for the title but I’m not sure how I should call it. I’m using PostgreSQL 8.3 and would be fine with non-ansi query proposals.

Suppose this schema:

TimeEntries
id              - int
entry_date      - date
tracked_seconds - int
project_id      - int

projects
id              - int
name            - string
path            - string

Projects are hirachical, I don’t care about parent_id etc. instead I opted for the path column, example:

Renovate Home    - path = renovate-home
- Clean Kitchen  - path = renovate-home/clean-kitchen

I want a query that returns the following:

date - project_path - tracked_seconds(this project) - tracked_seconds (total of self and child projects)

Grouped by date and multiple times per project path so example data:

projects
name          path
Funny         funny
- Project     funny/project
-- Is Funny   funny/project/is-funny
Foo           foo
- Bar         foo/bar

If there are now TimeEntries for funny/project and foo/bar and i Issue this query:

SELECT         entry_date, p.path as project_path, sum(tracked_seconds) / 60
FROM           time_entries te
LEFT JOIN      projects p on te.project_id = p.id
GROUP BY       entry_date, p.path

I get this result:

entry_date        project_path           ?sum?
2010-10-01        funny/project          20
2010-10-01        foo/bar                10

What I want is this:

entry_date        project_path           direct_sum     total
2010-10-01        funny                  0              20
2010-10-01        funny/project          20             20 
2010-10-01        foo                    0              10
2010-10-01        foo/bar                10             10
  • 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-05-18T07:33:02+00:00Added an answer on May 18, 2026 at 7:33 am

    Are you stuck with 8.3 or can you upgrade to 8.4?

    Because with 8.4, I think this could be solved using windowing functions:

    SELECT te.entry_date, 
           te.tracked_seconds, 
           p.path, 
           sum(tracked_seconds) over (partition by (string_to_array(path, '/'))[1] order by entry_date asc, path desc)
    FROM TimeEntries te
     JOIN projects p ON te.project_id = p.id
    ORDER BY entry_date  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2008: Sorry for the possibly non-informative title but I'm not sure quite
hi sorry for the bad title but I'm not 100% sure what I need
sorry if the title is very confusing, but I'm not sure how to really
Sorry for the vague title but I'm not quite sure how to phrase this.
I am sorry for the title but I really do not know how to
Sorry if the title is not that specific, but I don't know how else
I'm sorry if this title doesn't describe the problem properly but I wasn't sure
Sorry for the non-technical title, but I think it summarizes my question well. If
Sorry for the non-descriptive title but I don't know whether there's a word for
Sorry the title is not very descriptive but it is a tricky problem to

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.