Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Language: SQL Server
Expertise: Beginner
Oct 8, 1999



Application Security Testing: An Integral Part of DevOps

Doing a GROUP BY Statement

How do I do a "group by" SQL statement? I want to return all rows and columns with ** records. Here is the data sample:
columnA columnB columnC
AAA      2334   jan/01/99 **
AAA         4   mar/05/99 
BBB        32   feb/20/99 
BBB         3   feb/23/99
BBB        32   feb/24/99 **
CCC     32439   jan/23/99 **
DDD       666   may/01/99 
EEE       444   mar/03/99 **
  • SELECT columnA columnB columnC
  • GROUP BY ColumnA
  • columnC <= mar/04/99 and the max row, which is in the same group

What's required is to treat this problem in two passes.

First isolate the records that are the case by selecting the max of Column B grouped by Column A. That will at least get you the highest value for the group.

Next, you need another pass to eliminate the outlying dates.

Sorry this solution isn't more elegant.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.
Thanks for your registration, follow us on our social networks to keep up-to-date