Introduction to PowerBuilder

HomePrevious Lesson: Sorting the Result Set
Next Lesson: Having Clause

Group By Clause

This allows you to group your data on one or more columns. For example, you might choose to group your data on transaction type. This might be useful for departments interested in a particular transaction type. Grouping allows you to put more structure into the data by simply rearranging them.

The following query lists all the transaction dates and total receipts of Unit measurement type products for that day.
SELECT "trans"."tran_date",
       sum("trans"."tran_qty")
   FROM "trans",
        "product_master"
   WHERE "product_master"."product_no" = 
         "trans"."tran_item_no" AND
         "trans"."tran_type" = 'R' AND
         "product_master"."product_measuring_unit" = 'U'
	GROUP BY "trans"."tran_date"  

When using Adaptive Server Anywhere database, you must include every non-aggregate column that is to be displayed in the GROUP BY clause of the DataWindow.

This effectively invalidates the usefulness of grouping data, but with some other databases such as Sybase Adaptive Server, it isn't necessary to include all the columns in the GROUP BY clause.
HomePrevious Lesson: Sorting the Result Set
Next Lesson: Having Clause