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 8620069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:29:34+00:00 2026-06-12T06:29:34+00:00

I have a single table which stores bandwidth usage on the network over a

  • 0

I have a single table which stores bandwidth usage on the network over a period of time. One column will contain the date time (primary key) and another column will record the bandwidth. Data is recorded every minute. We will have other columns recording other data at that moment in time.

If the user requests the data on 15 minute intervals (within a 24 hour period given start and end date), is it possible with a single query to get the data I require or would I have to write a stored procedure/cursor to do this? Users may then request 5 minute intervals data etc.

I will most likely be using Postgres but are there other NOSQL options which would be better?

Any ideas?

  • 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-12T06:29:35+00:00Added an answer on June 12, 2026 at 6:29 am
    WITH t AS (
       SELECT ts, (random()*100)::int AS bandwidth
       FROM   generate_series('2012-09-01', '2012-09-04', '1 minute'::interval) ts
       )
    
    SELECT date_trunc('hour', ts) AS hour_stump
          ,(extract(minute FROM ts)::int / 15) AS min15_slot
          ,count(*) AS rows_in_timeslice               -- optional
          ,sum(bandwidth) AS sum_bandwidth
    FROM   t
    WHERE  ts >= '2012-09-02 00:00:00+02'::timestamptz -- user's time range
    AND    ts <  '2012-09-03 00:00:00+02'::timestamptz -- careful with borders 
    GROUP  BY 1, 2
    ORDER  BY 1, 2;
    

    The CTE t provides data like your table might hold: one timestamp ts per minute with a bandwidth number. (You don’t need that part, you work with your table instead.)

    Here is a very similar solution for a very similar question – with detailed explanation how this particular aggregation works:

    • date_trunc 5 minute interval in PostgreSQL

    Here is a similar solution for a similar question concerning running sums – with detailed explanation and links for the various functions used:

    • PostgreSQL: running count of rows for a query 'by minute'

    Additional question in comment

    WITH -- same as above ...
    
    SELECT DISTINCT ON (1,2)
           date_trunc('hour', ts) AS hour_stump
          ,(extract(minute FROM ts)::int / 15) AS min15_slot
          ,bandwidth AS bandwith_sample_at_min15
    FROM   t
    WHERE  ts >= '2012-09-02 00:00:00+02'::timestamptz
    AND    ts <  '2012-09-03 00:00:00+02'::timestamptz
    ORDER  BY 1, 2, ts DESC;
    

    Retrieves one un-aggregated sample per 15 minute interval – from the last available row in the window. This will be the 15th minute if the row is not missing. Crucial parts are DISTINCT ON and ORDER BY.
    More information about the used technique here:

    • Select first row in each GROUP BY group?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single product table with multiple fields which contain user evaluations of
I currently have a table which only has a single editable column. I have
I have an invoices table which stores a single record for each invoice, with
I have a table which needs to be scrollable within a single page. I've
I have a huge access mdb file which contains a single table with 20-30
I'm working on a project that will have a single table holding lots and
I currently have a table which stores a load of statistics such as views,
Our application has a table which stores all transactions records of clients in one
I have a database made up a single table with several fields, one of
I have a database table (MySQL 5) which stores file hashes and filenames. I

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.