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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:06:36+00:00 2026-06-11T13:06:36+00:00

I’m trying to select some traffic flow data and create sums for the different

  • 0

I’m trying to select some traffic flow data and create sums for the different traffic directions, bucketed in 60 second buckets. Simplified table is below (timestamp is unix epoch):

Timestamp      Source     Destination    Count
1              inside     outside          5
2              inside     outside          6
3              outside    inside           7
65             inside     inside           4
66             inside     outside          6
72             inside     outside          7

Current Query (which does the bucketing, but doesn’t have anything about direction)

SELECT sum(count) AS total FROM table GROUP BY round(timestamp/60)

This gives me the total count for each 60 second “bucket” like

Count
 18
 10
 7

Now, where I’m lost (I can do this in the client code, but I’d kinda like to do it with the SQL if possible). I’d like to have a sum called inbound for every row with inside as source and dest as outside, a sum called outbound for every row with outside in source and inside as dest, and a row called internal where both source and dest are inside. Still grouped by the 60 second bucket. i.e. what I want back is:

Inbound  Outbound  Internal
   7        11        0
   0         6        4
   0         7        0

My SQL foo is weak, and I really don’t know where to start (I suspect I need a subselect, but I’m not sure how to construct it).

  • 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-11T13:06:37+00:00Added an answer on June 11, 2026 at 1:06 pm

    You should actually be able to do a pivot:

    SELECT SUM(count) AS total
        , SUM(CASE 
                  WHEN Source = 'outside' 
                       AND Destination = 'inside' 
                       THEN count  -- Use 1 if you only want to count each row
                  ELSE 0 END) AS [Inbound]
        , SUM(CASE
                  WHEN Source = 'inside' 
                      AND Destination = 'outside' 
                      THEN count
                  ELSE 0 END) AS [Outbound]
        , SUM(CASE 
                  WHEN Source = 'inside'
                      AND Destination = 'inside' 
                      THEN count
                  ELSE 0 END) AS [Internal]
    FROM table 
    GROUP BY round(timestamp/60)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.