Group By

  • I have a table and I want to sum a couple of fields. I also want to display multiple fields, but I don't want them to actually control my grouping. I just want them to display and no grouping on them. Is this possible? I see that every field I use in my select, must be in the group by.

    Thanks

  • You can do a MAX() or MIN() on those columns.

  • How do you use Max()/Min() when you're trying to sum columns. I thought these functions will return the max and min values not a summation.

  • you can't do ir directly in the same query.

    All the field with no functions must be in the group by. But I guess you could create views, or temp tables with the result that you need and then you can query that table/view.

  • Yes, you can use the Max like:

    Select StoreName, Max(Employee), Sum(Revenue) From StoreData Group By StoreName

    The Sum() will sum all of the data by the grouping, and the Max() or Min() will take the Min or Max value of each grouping.

    Give it a try and see if it gives you the results you are looking for.

    If this is not the type of results you need, then you may need to work with temp tables as rscosta mentioned.

    Dan

    Edited by - DanG on 05/15/2003 06:09:58 AM

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply