Example: Using Functions in Queries

Objective: Get statistics on clients by countries (i.e. the number of clients from each country).

1. Drag & drop the tables CLIENTS and COUNTRIES to the working area. In the CLIENTS table check the COUN_ID field, and also the COUN_NAME field in the COUNTRIES table.

 

 

2. Set the connection between the tables CLIENTS and COUNTRIES by the unique field COUN_ID: click and hold left mouse button on the COUN _ID field in the CLIENTS table, drag it to the COUN _ID field in the COUNTRIES table, and release the button. As a result you get the following:

 

 

3. Now you need to specify the selection conditions. Set the necessary sorting order: number of countries (in the CLIENTS table) — descending, names of the countries — ascending). For the COUN_ID field choose the Count function, and also set grouping by country name:

 

 

4. After the request model was created, click the Generate Query button. The SQL code of the request will be generated and displayed in the Content field of the Query tab.

 

 

5. You can view the results by clicking the Run Query button. You will get the table with countries rating according to the number of your clients from each country. For example:

 

 

6. To save the request model switch to the Query tab, specify the Query Name and Description (optionally) and click OK.

Note: You can export or print these data from the Queries tab of the Server Administrator Corporate Settings (using the Export Data and Print Data buttons) (the query should be saved as described in the previous paragraph).

 

 

See also:

Query Building Tutorial