473,388 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

a question about "group by"

There is a basic sql below:
SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs

I want to get results by grouping by the field LocalPort and
RemotePort, I try it like this:

SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs
WHERE Source='137.72.43.114' and Destination='137.72.43.247'
GROUP BY LocalPort, RemotePort
ORDER BY TimeStamp;
It's error, then I modified it like this:

SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs
WHERE Source='137.72.43.114' and Destination='137.72.43.247'
GROUP BY SourcePort, DestPort, CTEnr, TimeStamp, DatagramSize, Source,
Destination, Protocol, Messages
ORDER BY TimeStamp;
It works fine, but it's not grouping!

I want to know why? And, how can I get results by grouping by the field
LocalPort and RemotePort?
Best Regards,

Thomas

Oct 13 '06 #1
1 1713
Thomas Qi wrote:
There is a basic sql below:
SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs

I want to get results by grouping by the field LocalPort and
RemotePort, I try it like this:

SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs
WHERE Source='137.72.43.114' and Destination='137.72.43.247'
GROUP BY LocalPort, RemotePort
ORDER BY TimeStamp;
It's error, then I modified it like this:

SELECT CTEnr AS ID, TimeStamp, DatagramSize, Source AS LocalIP,
Destination AS RemoteIP, Protocol, Messages, SourcePort AS LocalPort,
DestPort AS RemotePort
FROM SelectedRecs
WHERE Source='137.72.43.114' and Destination='137.72.43.247'
GROUP BY SourcePort, DestPort, CTEnr, TimeStamp, DatagramSize, Source,
Destination, Protocol, Messages
ORDER BY TimeStamp;
It works fine, but it's not grouping!

I want to know why? And, how can I get results by grouping by the
field LocalPort and RemotePort?
Best Regards,

Thomas
You must aggregate on all of the fields that you aren't grouping by. If you
have 50 records with the same value in the field(s) you are grouping on then for
every other field you have 50 possible rows to return. You have to tell the
query whether you want the Min, Max, Sum, First, etc., or it has no idea which
of those 50 possible row values to return.

If you group by all fields then you are not grouping at all.

In the query grid just specify some sort of aggregation besides Group By on all
of the fields that you are not grouping on. Yes this does mean that you might
not get everything you want out of the query. Totals queries are used for very
specific tasks and you sometimes have to combine them with other queries to get
all the data you want.

--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com


Oct 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tamer Higazi | last post by:
Hi! I have problems creating joins between tables and to limit rows for a specified clolumn. I have 2 tables! employees departments I face the problems with the GROUP BY clause and i don't...
2
by: mark | last post by:
How can I use "Group By" or a formula to group my query results in 1-year periods from a given date, e.g. 3 groups: 1 Sept 2001 - 1 Sept 2002 1 Sept 2002 - 1 Sept 2003 1 Sept 2003 - 1 Sept 2004 ...
0
by: TaeHo Yoo | last post by:
After running my code, group tree(the left section of the report) changes but not the content in the report. My code is ---------------------------------------------------------- Private Sub...
4
by: Phill W. | last post by:
Is there anything amiss with the newsgroup microsoft.public.dotnet.vb.general ?? From where I'm sitting, it's /completely/ dried up - only four posts in as many days. Did I miss the mass...
5
by: Dave Smithz | last post by:
Hi there, Been working on an evolving DB program for a while now. Suddenly I have come across a situation where I need to update a table based on a group by query. For example, I have a table...
1
by: ASF | last post by:
Is it possible to create a crystal report graph in which a user selects some parameters---a date range for instance--- AND the table field that they wish to "Group By" then hits the submit button...
2
by: nico3334 | last post by:
Hi, I have a SQL table that has data like this: Title Month Info 1 ---- 7 ---- 100 1 ---- 7 ---- 100 1 ---- 8 ...
2
by: BrightFuture | last post by:
I'm fairly new to detailed data analysis. A lot of my queries end up using the Group By function, but other than knowing when to use it, I don't understand how it works. All I'm doing is hitting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.