Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Ilenko_YU.I._Stvorennya_baz_danih_u_seredov._MS...doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
3.6 Mб
Скачать

3.2 Example of queries creation for database “Product realization of Holding company “Group nord”

3.2.1 A select queries

With the help of query «Orders» select data about all product orders in Holding company “Group NORD” with fields: «Model», «Characteristic», «Product group», «Customer», «Date».

In the Database window, click the Queries icon in the Objects bar and double-click Create query in Design view. Add all tables to your new query. By double-clicking add the fields Model, Characteristic, Product group, Customer, Date to the design grid.

Create a new field Cost_of_order. For a new blank field use Build… (from the context menu or from the toolbar).

Cost_of_order: [Realization]![Amount]*[Catalog_of_products]![Price]

Save the query with name «Orders».

3.2.2 A select queries with criteria

3.2.2.1 A select queries with criteria «Orders from 15.11.2011»

This query we create on the basis of tables. By double-clicking add the fields Model, Characteristic, Product group, Customer, Date to the design grid.

Create a new field Cost_of_order. For a new blank field use Build… .

Cost_of_order: [Realization]![Amount]*[Catalog_of_products]![Price]

For the filed Date enter the criteria in the design grid's Criteria row:

#15.11.2011#

The field Date we not display in the query results – uncheck the "Show" box for this field.

Save the query with name «Orders from 15.11.2011».

3.2.2.2 A select queries with criteria «Orders on refrigerators»

This query we create on the basis of query «Orders», choose all fields of it. For For the filed Characteristic enter the criteria in the design grid's Criteria row:

Like “*refrig*”

The filed Characteristic should not be displayed in the query results.

Save the query.

3.2.2.3 A select queries «Orders of the current month».

This query we create on the basis of query «Orders», add all fields of it.

Calculate a new field Order_Month using Build… .

Order_Month: Month([Date])

Calculate a new field Order_Year using Build… .

Order_Year: Year([Date])

For the filed Order_Month enter the criteria in the design grid's Criteria row:

Month(Date())

For the filed Order_Year enter the criteria in the design grid's Criteria row:

Year(Date())

The fileds Order_Month and Order_Year should not be displayed in the query results.

Save the query.

3.2.3 An aggregate query «Total amount of orders by product groups»

Create a query on the basis of tables. By double-clicking add the field Product group to the design grid.

Create a new field Cost_of_order using Build… .

Cost_of_order: [Realization]![Amount]*[Catalog_of_products]![Price]

Click on the Totals icon on the toolbar or use View - Totals.

For the field Cost_of_order in the Total row choose the function Sum.

Save the query. The query result:

3.2.4 A parameter query «An information about concrete client orders»

Create a query on the basis of tables. By double-clicking add the fields Customer, Model, Characteristic to the design grid.

Create a new field Cost_of_order using Build… .

Cost_of_order: [Realization]![Amount]*[Catalog_of_products]![Price]

For the filed Customer enter the criteria in the design grid's Criteria row:

[Enter a customer]

Save the query. When you run a query a box will pop up asking you to fill in the criteria to be searched for.

3.2.5 An update query «Multiply price on product group Vacuums by 10%»

Add tables Catalog_of_products and Catalog_of_product_groups.

From the main menu choose Query – Update query. A new row labeled Update To will be added to the query form. Add all fields required for your search criteria as well as the fields to be updated (fields Price and Product_group).

Enter the criteria for the records that are to be updated. For the field Product_group enter the criteria “Vacuums”.

Enter the new data or an expression (formula) in the Update To section of the field(s) to be updated. For the field Price: [Price]*1,1

Save the query. It is created with icon . Run a query by clicking the Run button on the toolbar. The query update prices in the table Catalog_of_products.

3.2.6 Making a new table

The “Make Table” query allows you to create a new table from all or part of the data in one or more existing tables.

You can use this type of query for such things as making backup copies, archiving data in separate tables, and creating specific tables for exporting data to other databases or applications.

To create a new table based on a sub-set of records contained within an existing table, follow these steps:

1. Access the query form design window. This query we create on the basis of query «Orders». Add all fields to the query that should be included in the new table.

2. From the main menu choose Query – Make - Table query.

3. Enter a name for the new table “All orders”.

Click on Run button to actually perform the query. A warning box appears listing the number of records (rows) that will be added to the new table. Click on YES to confirm the creation of the table.

If you re-run the query, Access will delete the previous version of the table and recreate the table from your current query.

3.2.7 A "crosstab query" which select data about cost of product realization by product groups and dates

This query let’s create on the basis of query «Orders», add fields Product group, Date, Cost_of_order.

On the toolbar, click Query Type , and then click Crosstab.

For the field Product group whose values you want to appear as row headings, click the Crosstab row, and then click Row Heading. You must leave the default Group By in the Total row for this field.

For the field Data whose values you want to appear as column headings, click the Crosstab row, and then click Column Heading. You can choose Column Heading for one field only, and you must leave Group By in the Total row for this field.

For the field Cost_of_order click the Crosstab row, and then click Value and you should choose Sum in the Total row for this field.

Save and run a query by clicking the Run button on the toolbar. Table view:

3.2.8 A delete query

Create a new query to delete all records in the table Catalog_of_products that contains an information about refrigerators with a single chamber.

Add the table Catalog_of_products and then the field Characteristic needed for specifying the criteria to the design grid.

Set a type of this query Query – Delete Query.

For the filed Characteristic enter the criteria in the design grid's Criteria row:

Like “*single chamber*”

Click on the Run button to actually perform the query. You will be asked to confirm the deletion.

In the result query deletes from Catalog of product table all records which have symbols «single chamber» in the field Characteristic.