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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:00:04+00:00 2026-05-13T17:00:04+00:00

I’ve got SQL Compact Database that contains a table of IP Packet Headers. The

  • 0

I’ve got SQL Compact Database that contains a table of IP Packet Headers. The Table looks like this:

Table: PacketHeaders    

ID  SrcAddress  SrcPort  DestAddress  DestPort  Bytes
1   10.0.25.1   255      10.0.25.50   500       64
2   10.0.25.50  500      10.0.25.1    255       80
3   10.0.25.50  500      10.0.25.1    255       16
4   75.48.0.25  387      74.26.9.40   198       72
5   74.26.9.40  198      75.48.0.25   387       64
6   10.0.25.1   255      10.0.25.50   500       48

I need to perform a query to show ‘conversations’ going on across a local network. Packets going from A -> B is part of the same conversations as packets going from B -> A. I need to perform a query to show the on going conversations. Basically what I need is something that looks like this:

Returned Query:

SrcAddress  SrcPort  DestAddress  DestPort  TotalBytes  BytesA->B  BytesB->A
10.0.25.1   255      10.0.25.50   500       208         112        96
75.48.0.25  387      74.26.9.40   198       136         72         64

As you can see I need the query (or series of queries) to recognize that A->B is the same as B->A and break up the byte counts accordingly. I’m not a SQL guru by any means but any help on this would be greatly appreciated.

  • 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-13T17:00:04+00:00Added an answer on May 13, 2026 at 5:00 pm

    Try this:

    SELECT
        T1.SrcAddress,
        T1.SrcPort,
        T1.DestAddress,
        T1.DestPort,
        T1.Bytes + COALESCE(T2.Bytes, 0) AS TotalBytes,
        T1.Bytes AS A_to_B,
        COALESCE(T2.Bytes, 0) AS B_to_A
    FROM (
        SELECT SrcAddress, SrcPort, DestAddress, DestPort, SUM(Bytes) AS Bytes
        FROM PacketHeaders
        GROUP BY SrcAddress, SrcPort, DestAddress, DestPort) AS T1
    LEFT JOIN (
        SELECT SrcAddress, SrcPort, DestAddress, DestPort, SUM(Bytes) AS Bytes
        FROM PacketHeaders
        GROUP BY SrcAddress, SrcPort, DestAddress, DestPort) AS T2
    ON T1.SrcAddress = T2.DestAddress
    AND T1.SrcPort = T2.DestPort
    AND T1.DestAddress = T2.SrcAddress
    AND T1.DestPort = T2.SrcPort
    WHERE T1.SrcAddress < T1.DestAddress OR
        (T1.SrcAddress = T1.DestAddress AND T1.SrcPort = T1.DestPort) OR
        T2.DestAddress IS NULL
    

    On this test data:

    CREATE TABLE PacketHeaders (ID INT, SrcAddress NVARCHAR(100), SrcPort INT, DestAddress NVARCHAR(100), DestPort INT, Bytes INT);
    INSERT INTO PacketHeaders (ID, SrcAddress, SrcPort, DestAddress, DestPort, Bytes) VALUES
    (1, '10.0.25.1', 255, '10.0.25.50', 500, 64),
    (2, '10.0.25.50', 500, '10.0.25.1', 255, 80),
    (3, '10.0.25.50', 500, '10.0.25.1', 255, 16),
    (4, '75.48.0.25', 387, '74.26.9.40', 198, 72),
    (5, '74.26.9.40', 198, '75.48.0.25', 387, 64),
    (6, '10.0.25.1', 255, '10.0.25.50', 500, 48),
    (7, '10.0.25.2', 255, '10.0.25.50', 500, 48),
    (8, '10.0.25.52', 255, '10.0.25.50', 500, 48);
    

    This gives the following results:

    '10.0.25.1', 255, '10.0.25.50', 500, 208, 112, 96
    '10.0.25.2', 255, '10.0.25.50', 500, 48, 48, 0
    '10.0.25.52', 255, '10.0.25.50', 500, 48, 48, 0
    '74.26.9.40', 198, '75.48.0.25', 387, 136, 64, 72
    

    The way it works is to first group one-way conversations and total the byte counts. This assures that every conversation will be represented exactly twice – once for each direction. This result is then self-joined to give the result you need, filtering the duplicates by enforcing that the (address, port) of A must be less than B. A left join is used to allow one-way conversations.

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

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Personally I tend to use the filesystem Pro DB Can… May 14, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer NSSortDescriptor should be initialised with a key string for a… May 14, 2026 at 7:06 pm
  • Editorial Team
    Editorial Team added an answer Be sure to init your cell with the style UITableViewCellStyleSubtitle May 14, 2026 at 7:06 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.