We now go back to the function. Remember that we use the SUM instruction to calculate all Sales! What should I do if our needs becomes a turnover (Sales) for each store (Sales)? In this case, we have to do two things: First, we have to choose from the two fields of Store_name and Sales. Second, we need to confirm that all Sales is in accordance with each store_name. This syntax is:
SELECT "field 1", sum ("field 2") from "GROUP BY" field 1 "
In our example,
Store_information form
Saos Angeles $ 1500 Jan-05-1999 San Diego $ 250 Jan-07-1999 Los Angeles $ 300 JAN-08-1999 Boston $ 700 JAN-08-1999
We will be entered.
Select Store_name, Sum (Sales) from store_information group by store_name
result:
Store_NameSum (Sales) LOS Angeles $ 1800SAN Diego $ 250Boston $ 700
When we choose not only one field, and at least one of the columns have the use of functions, we need to use the group by this instruction. In this case, we need to determine that we have all other fields. In other words, in addition to including the fields including the function, we need to put it in the clause of Group By.