sql server - Combining SQL Rows -
I have got a SQL compact database in which there is a table of IP packet headers
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 Table Looks Like This 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 'Conversation' running on a local network. A query to show Packets going from A -> B is part of the conversation as is the packet going from B -> A. I need to make a query to the conversation I actually have what I want, which looks something like this: returns to the question: SrcAddress SrcPort DestAddress DestPort TotalBytes bytes E & gt; B bytesby-> A10.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 that I can query query (or query series) ), A-> BB-> A and byte are calculated accordingly accordingly. I'm not a SQL master in any way, but any help on this would be greatly appreciated.
this:
select T1.SrcAddress, T1. SrcPort, T1.DestAddress, T1.DestPort, T1.Bytes + COALESCE (T2.Bytes, as 0) as TotalBytes, T1.Bytes A_to_B, Kolses (T2 in bytes, a) (selected Bi_to_a SrcAddress , SrcPort, DestAddress, DestPort, SUM (bytes) aS bytes packet PacketHeaders bytes as by headers Group SRC address, Sarseeport, Destadres, Destport) aS T1 left join (Saarsiadres, Sarseeport, Destadres, DestPort, SUM (bytes) Group by State SrcAddress, SrcPort, DestAddress, DestPort) as T 2 T1.SrcAddress = T2.DestAddress and T1.SrcPort = T2.DestPort and T1.DestAddress = T2.SrcAddress and T1. DestPort = T2.SrcPort WHERE T1.SrcAddress & lt; T1.DestAddress or (T1.SrcAddress = T1.DestAddress and T1.SrcPort = T1.DestPort) or T2.DestAddress zero
The test data:
CREATE tABLE packet headers (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.55.55 ', 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.20.50', 500, 48), (7, '10.0.25.2 ', 255, '10.0.25.50', 500, 48), (8, '10.0.25.52 ', 255, '10.05.55', 500, 48);
This gives the following results:
'10.0.25.1 ', 255, '10.0.25.50', 500, 208, 112 , 96'10.0.0.225.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 ', 1987, '75.48.0.25', 387, 136, 64, 72
The way it works, the same one -Star is a group of conversations and bytes total number assures that every conversation will be displayed twice every time - once for every direction This result then connects with itself to get results, so that duplicate is applied by filtration that should be less than A (address, port) B. A left join is used to perform a one-way conversation.
Comments
Post a Comment