Kontsulta-diseinua

Kontsulta-diseinuaren ikuspegiak datu-baseko kontsultak sortzeko eta editatzea ahalbidetzen du.

Komando hau erabiltzeko...

Datu-baseen fitxategi-leihoan, egin klik Kontsultak ikonoan, ondoren aukeratu Editatu - Editatu.


note

Datu-base askok kontsultak erabiltzen dituzte datu-baseko taulak iragazteko edo ordenatzeko eta horrela ordenagailuan erregistroak bistaratzeko. Ikuspegiek kontsulten funtzionalitate bera eskaintzen dute, baina zerbitzariaren aldetik. Datu-basea ikuspegiak onartzen dituen zerbitzari batean badago, ikuspegiak zerbitzariko erregistroak iragazteko erabil daitezke, horrela bistaratze-denbora azkartzeko.


note

Datu-baseko dokumentu baten Taulak fitxako Sortu ikuspegia komandoa hautatzen bada, Ikuspegi-diseinua leihoa ikusiko da. Leiho hori hemen deskribatutako Kontsulta-diseinua leihoaren antzekoa da.


'Kontsulta-diseinua' leihoaren diseinua sortutako kontsulta batekin gordetzen da, baina ezin da sortutako ikuspegi batekin gorde.

Diseinu-ikuspegia

Kontsulta bat sortzeko, egin klik datu-baseko dokumentu baten Kontsultak ikonoan, eta gero, sakatu Sortu kontsulta diseinu-ikuspegian.

The lower pane of the Design View is where you define the query. To define a query, specify the database field names to include and the criteria for displaying the fields. To rearrange the columns in the lower pane of the Design View, drag a column header to a new location, or select the column and press +arrow key.

In the top of the query Design View window, the icons of the Query Design Bar and the Design bar are displayed.

Kontsulta bat probatu nahi bada, egin klik bikoitza datu-baseko dokumentuko kontsulta-izenean. Kontsultaren emaitza datu-iturburuaren ikuspegiaren antzeko taula batean bistaratuko da. Oharra: bistaratutako taula behin-behinekoa da.

Kontsultaren diseinu-ikuspegiko teklak

Tekla

Funtzioa

F4

Aurreikusi

F5

Exekutatu kontsulta

F7

Gehitu taula edo kontsulta


Arakatu

Kontsulta-diseinua lehen aldiz irekitzen denean, elkarrizketa-koadro bat agertzen da, kontsulta berriaren oinarria izango den taula edo kontsulta hautatzeko.

Egin klik bikoitza kontsultari gehitu beharreko eremuetan. Erlazioak definitzeko, arrastatu eta jaregin.

note

Kontsulta diseinatzean ezin dira hautatutako taulak aldatu.


Kendu taulak

Taula diseinu-ikuspegitik kentzeko, egin klik taula-leihoaren goiko ertzean eta ireki laster-menua. Ezabatu komandoa erabili daiteke taula diseinu-ikuspegitik kentzeko. Beste aukera bat 'Ezabatu' tekla sakatzea da.

Aldatu taula lekuz eta aldatu bere tamaina

Hobespenen arabera, taulak tamainaz aldatu eta antolatu daitezke. Taulak lekuz aldatzeko, arrastatu goiko ertza nahi den kokalekura. Handitu edo txikitu taularen tamaina saguaren kurtsorea ertzean edo izkinan kokatuz, eta ondoren, arrastatu taula nahi den tamaina eman arte.

Taulen arteko erlazioak

Taula bateko eremu-izenaren eta beste taula bateko eremu-izenaren artean erlazioa baldin badago, erlazio hori kontsultarako erabili daiteke.

If, for example, you have a spreadsheet for articles identified by an article number, and a spreadsheet for customers in which you record all articles that a customer orders using the corresponding article numbers, then there is a relationship between the two "article number" data fields. If you now want to create a query that returns all articles that a customer has ordered, you must retrieve data from two spreadsheets. To do this, you must inform LibreOffice about the relationship which exists between the data in the two spreadsheets.

To do this, click a field name in a table (for example, the field name "Item-Number" from the Customer table), hold down the mouse button and then drag the field name to the field name of the other table ("Item-Number" from the Item table). When you release the mouse button, a line connecting the two fields between the two table windows appears. The corresponding condition that the content of the two field names must be identical is entered in the resulting SQL query.

Erlazionatuta dauden hainbat orritan oinarritutako kontsulta bat sortzeko, LibreOffice erabili behar da datu-base erlazional baten interfaze gisa.

note

Ezin dira datu-base desberdinetako taulak atzitu kontsulta batean. Taula anitz hartzen dituzten kontsultak datu-base bakar baten barruan soilik sortu daitezke.


Erlazio mota zehaztae

If you double-click on the line connecting two linked fields or call the menu command Insert - New Relation, you can specify the type of relation in the Relations dialog.

Alternatively, press Tab until the line is selected, then press Shift+F10 to display the context menu and there choose the command Edit. Some databases support only a subset of the possible join types.

Erlazioak ezabatzea

Bi taularen arteko erlazioa ezabatzeko, egin klik konexio-marran eta sakatu Delete tekla.

Alternatively, delete the respective entries in Fields involved in the Relations dialog. Or press Tab until the connecting vector is displayed highlighted, then press Shift+F10 to open the context menu and select Delete command.

Kontsulta definitzea

Select conditions to define the query. Each column of the design table accepts a data field for the query. The conditions in one row are linked with a Boolean AND.

Eremu-izenak zehaztea

First, select all field names from the tables that you want to add to the query. You can do this either by drag-and-drop or by double-clicking a field name in the table window. With the drag-and-drop method, use the mouse to drag a field name from the table window into the lower area of the query design window. As you do this, you can decide which column in the query design window will receive the selected field. A field name can also be selected by double-clicking. It will then be added to the next free column in the query design window.

Eremu-izenak ezabatzea

Kontsultatik eremu-izen bat kentzeko, egin klik eremuaren zutabe-goiburukoan eta aukeratu Ezabatu komandoa zutabearen laster-menuan.

Kontsulta gordetzea

Kontsulta gordetzeko, erabili 'Estandarra' tresna-barrako Gorde ikonoa. Kontsulari izen bat emateko elkarrizketa-koadro bat agertuko da. Datu-baseak eskemak onartzen baditu, eskema-izen bat ere zehaztu daiteke.

Eskema

Sartu kontsultari edo taula-ikuspegiari esleitu zaion eskemaren izena.

Kontsultaren izena edo taula-ikuspegiaren izena

Sartu kontsultaren edo taula-ikuspegiaren izena.

Datuak iragaztea

To filter data for the query, set the desired criteria in the lower area of the query design window. The following options are available:

Field

Enter the name of the data field that is referred to in the Query. All settings made in the filter option rows refer to this field. If you activate a cell here with a mouse click you'll see an arrow button, which enables you to select a field. The "Table name.*" option selects all data fields with the effect that the specified criteria will be applied to all table fields.

Alias

Specifies an alias. This alias will be listed in the query instead of the field name. This makes it possible to use user-defined column labels. For example, if the data field is named PtNo and, instead of that name, you would like to have PartNum appear in the query, enter PartNum as the alias.

In a SQL statement, aliases are defined as follows:

SELECT column AS alias FROM table.

For example:

SELECT "PtNo" AS "PartNum" FROM "Parts"

Table

The corresponding database table of the selected data field is listed here. If you activate this cell with a mouse click, an arrow will appear which enables you to select a different table for the current query.

Sort

If you click on this cell, you can choose a sort option: ascending, descending and unsorted. Text fields will be sorted alphabetically and numerical fields numerically. For most databases, administrators can set the sorting options at the database level.

Visible

If you mark the Visible property for a data field, that field will be visibly displayed in the resulting query. If you are only using a data field to formulate a condition or make a calculation, you do not necessarily need to display it.

Criteria

Specifies a first criteria by which the content of the data field is to be filtered.

or

Here you can enter one additional filter criterion for each line. Multiple criteria in a single column will be interpreted as boolean OR.

You can also use the context menu of the line headers in the lower area of the query design window to insert a filter based on a function:

Functions

The functions which are available here depend on those provided by the database engine.

If you are working with the embedded HSQL database, the list box in the Function row offers you the following options:

Option

SQL

Effect

No function

No function will be executed.

Average

AVG

Calculates the arithmetic mean of a field.

Count

COUNT

Determines the number of records in the table. Empty fields can either be counted (a) or excluded (b).

a) COUNT(*): Passing an asterisk as the argument counts all records in the table.

b) COUNT(column): Passing a field name as an argument counts only the records in which the specified field contains a value. Records in which the field has a Null value (i.e. contains no textual or numeric value) will not be counted.

Maximum

MAX

Determines the highest value of a record for that field.

Minimum

MIN

Determines the lowest value of a record for that field.

Sum

SUM

Calculates the sum of the values of records for the associated fields.

Group

GROUP BY

Groups query data according to the selected field name. Functions are executed according to the specified groups. In SQL, this option corresponds to the GROUP BY clause. If a criterion is added, this entry appears in the SQL HAVING sub-clause.


You can also enter function calls directly into the SQL statement. The syntax is:

SELECT FUNCTION(column) FROM table.

For example, the function call in SQL for calculating a sum is:

SELECT SUM("Price") FROM "Article".

Except for the Group function, the above functions are called Aggregate functions. These are functions that calculate data to create summaries from the results. Additional functions that are not listed in the list box might be also possible. These depend on the specific database engine in use and on the current functionality provided by the Base driver used to connect to that database engine.

To use other functions not listed in the list box, you must enter them manually under Field.

You can also assign aliases to function calls. If you do not want to display the query string in the column header, enter a desired substitute name under Alias.

The corresponding function in an SQL statement is:

SELECT FUNCTION() AS alias FROM table

Example:

SELECT COUNT(*) AS count FROM "Item"

note

If you run such a function, you cannot insert any additional columns for the query other than as an argument in a "Group" function.


Examples

In the following example, a query is run through two tables: an "Item" table with the "Item_No" field and a "Suppliers" table with the "Supplier_Name" field. In addition, both tables have a common field name "Supplier_No."

The following steps are required to create a query containing all suppliers who deliver more than three items.

  1. Insert the "Item" and "Suppliers" tables into the query design.

  2. Link the "Supplier_No" fields of the two tables if there is not already a relation of this type.

  3. Double-click on the "Item_No" field from the "Item" table. Display the Function line using the context menu and select the Count function.

  4. Enter >3 as a criterion and disable the Visible field.

  5. Double-click the "Supplier_Name" field in the "Suppliers" table and choose the Group function.

  6. Run the query.

If the "price" (for the individual price of an article) and "Supplier_No" (for the supplier of the article) fields exist in the "Item" table, you can obtain the average price of the item that a supplier provides with the following query:

  1. Insert the "Item" table into the query design.

  2. Double-click the "Price" and "Supplier_No" fields.

  3. Enable the Function line and select the Average function from the "Price" field.

  4. You can also enter "Average" in the line for the alias name (without quotation marks).

  5. Choose Group for the "Supplier_No" field.

  6. Run the query.

The following context menu commands and symbols are available:

Functions

Shows or hides a row for the selection of functions.

Table Name

Shows or hides the row for the table name.

Alias Name

Shows or hides the row for the alias name.

Distinct Values

Retrieves only distinct values from the query. This applies to multiple records that might contain several repeating occurrences of data in the selected fields. If the Distinct Values command is active, you should only see one record in the query (DISTINCT). Otherwise, you will see all records corresponding to the query criteria (ALL).

For example, if the name "Smith" occurs several times in your address database, you can choose the Distinct Values command to specify in the query that the name "Smith" will occur only once.

For a query involving several fields, the combination of values from all fields must be unique so that the result can be formed from a specific record. For example, you have "Smith in Chicago" once in your address book and "Smith in London" twice. With the Distinct Values command, the query will use the two fields "last name" and "city" and return the query result "Smith in Chicago" once and "Smith in London" once.

In SQL, this command corresponds to the DISTINCT predicate.

Limit

Allows you to limit the maximum number of records returned by a query.

If a Limit construction is added, you will get at most as many rows as the number you specify. Otherwise, you will see all records corresponding to the query criteria.

Formulating filter conditions

When formulating filter conditions, various operators and commands are available to you. Apart from the relational operators, there are SQL-specific commands that query the content of database fields. If you use these commands in the LibreOffice syntax, LibreOffice automatically converts these into the corresponding SQL syntax via an internal parser. You can also enter the SQL command directly and bypass the internal parser. The following tables give an overview of the operators and commands:

Operator

Esanahia

Condition is satisfied if...

=

honen berdina

... eremuaren edukia zehaztutako adierazpenaren berdina bada.

= eragilea ez da bistaratuko kontsulta-eremuetan. Balioa eragilerik gabe sartzen baduzu, = eragilea automatikoki hartuko da.

<>

ez da honen berdina

... eremuko edukia ez badagokio zehaztutako adierazpenari.

>

hau baino handiagoa da

... eremuaren edukia zehaztutako adierazpena baino handiagoa bada.

<

hau baino txikiagoa da

... eremuaren edukia zehaztutako adierazpena baino txikiagoa bada.

>=

hau baino handiagoa edo berdina da

... eremuaren edukia zehaztutako adierazpena baino handiagoa edo berdina bada.

<=

hau baino txikiagoa edo berdina da

... eremuaren edukia zehaztutako adierazpena baino txikiagoa edo berdina bada.


LibreOffice komandoa

SQL komandoa

Esanahia

Baldintza beteko da baldin eta...

IS EMPTY

IS NULL

nulua da

... eremuak ez du daturik. Hiru balizko egoera dituzten 'Bai/Ez' eremuetan, komando honek automatikoki kontsultatuko du zehaztu gabeko egoera (ez 'Bai' ez 'Ez').

IS NOT EMPTY

IS NOT NULL

ez dago hutsik

... eremua ez dago hutsik, hau da, datuak ditu.

LIKE

(*) leku-marka edozein karaktere kopururentzat

(?) leku-marka karaktere bakarrarentzat

LIKE

(%) leku-marka edozein karaktere kopururentzat

(_) leku-marka karaktere bakarrarentzat

honen elementua da

... datu-eremuak zehaztutako adierazpena badauka. (*) leku-markak adierazten du x adierazpena eremu-edukiaren hasieran (x*), amaieran (*x) edo barnean (*x*) agertzen den. SQL kontsultetan, SQL % karakterea edo LibreOffice interfazeko fitxategi-sistemako (*) leku-marka ezaguna sar ditzakezu leku-marka gisa.

(*) edo (%) leku-markek edozein karaktere kopuru adierazten dute. LibreOffice interfazeko galdera-ikurrak (?) edo SQL kontsultetako azpimarrak (_) karaktere bakarra adierazten dute.

NOT LIKE

NOT LIKE

ez da honen elementua

... eremuak ez badu zehaztutako adierazpena duen daturik.

BETWEEN x AND y

BETWEEN x AND y

[x,y] tartearen barnean dago

... eremuak x eta y balioen arteko datu-balioa badauka.

NOT BETWEEN x AND y

NOT BETWEEN x AND y

Ez dago [x,y] tartearen barnean

... eremuak x eta y balioen artean ez dagoen datu-balioa badauka.

IN (a; b; c...)

Kontuan izan puntu eta koma erabiltzen dela balio-zerrenden bereizle gisa!

IN (a, b, c...)

a, b, c... ditu

... eremu izenak zehaztutako adierazpenetako bat badauka: a, b, c,... Nahi adina adierazpen zehaztu daitezke eta kontsultaren emaitza OR boolear baten bidez bidez zehazten da. a, b, c... adierazpenak zenbakiak edo karaktereak izan daitezke

NOT IN (a; b; c...)

NOT IN (a, b, c...)

ez dauka a, b, c...

... eremuak ez badu zehaztutako adierazpenik: a, b, c,...

= TRUE

= TRUE

True (egia) balioa du

... eremu-izenak True (egia) balioa badu.

= FALSE

= FALSE

False (faltsua) balioa du

... eremuaren datu-balioa faltsua bada.


Adibideak

='Jn.'

"Jn." eremu-edukia duten eremu-izenak itzultzen ditu

<'2001-01-10'

returns dates that occurred before January 10, 2001

LIKE 'g?ve'

returns records with field content such as "give" and "gave".

LIKE 'S*'

returns records with field contents such as "Sun".

BETWEEN 10 AND 20

returns records with field content between the values 10 and 20. (The fields can be either text fields or number fields).

IN (1; 3; 5; 7)

returns records with the values 1, 3, 5, 7. If the field name contains an item number, for example, you can create a query that returns the item having the specified number.

NOT IN ('Smith')

returns records that do not contain "Smith".


Like Escape Sequence: {escape 'escape-character'}

Example: select * from Item where ItemName like 'The *%' {escape '*'}

The example will give you all of the entries where the item name begins with 'The *'. This means that you can also search for characters that would otherwise be interpreted as placeholders, such as *, ?, _, % or the period.

Outer Join Escape Sequence: {oj outer-join}

Example: select Article.* from {oj item LEFT OUTER JOIN orders ON item.no=orders.ANR}

Querying text fields

To query the content of a text field, you must put the expression between single quotes. The distinction between uppercase and lowercase letters depends on the database in use. LIKE, by definition, is case-sensitive (though some databases don't interpret this strictly).

Querying date fields

Date fields are represented as #Date# to clearly identify them as dates. Date, time and date/time constants (literals) used in conditions can be of either the SQL Escape Syntax type, or default SQL2 syntax.

Date Type Element

SQL Escape syntax #1 - may be obsolete

SQL Escape syntax #2

SQL2 syntax

Date

{D'YYYY-MM-DD'}

{d 'YYYY-MM-DD'}

'YYYY-MM-DD'

Time

{D'HH:MM:SS'}

{t 'HH:MI:SS[.SS]'}

'HH:MI:SS[.SS]'

DateTime

{D'YYYY-MM-DD HH:MM:SS'}

{ts 'YYYY-MM-DD HH:MI:SS[.SS]'}

'YYYY-MM-DD HH:MI:SS[.SS]'


Example: select {d '1999-12-31'} from world.years

Example: select * from mytable where years='1999-12-31'

All date expressions (date literals) must be enclosed with single quotation marks. (Consult the reference for the particular database and connector you are using for more details.)

Querying Yes/No fields

To query Yes/No fields, use the following syntax for dBASE tables:

Status

Query criterion

Example

Yes

for dBASE tables: not equal to any given value

=1 returns all records where the Yes/No field has the status "Yes" or "On" (selected in black),

No

.

=0 returns all records for which the Yes/No field has the status "No" or "Off" (no selection).

Null

IS NULL

IS NULL returns all records for which the Yes/No field has neither of the states Yes or No (selected in gray).


note

The syntax depends on the database system used. You should also note that Yes/No fields can be defined differently (only 2 states instead of 3).


Parameter queries

Parameter queries allow the user to input values at run-time. These values are used within the criteria for selecting the records to be displayed. Each such value has a parameter name associated with it, which is used to prompt the user when the query is run.

Parameter names are preceded by a colon in both the Design and SQL views of a query. This can be used wherever a value can appear. If the same value is to appear more than once in the query, the same parameter name is used.

In the simplest case, where the user enters a value which is matched for equality, the parameter name with its preceding colon is simply entered in the Criterion row. In SQL mode this should be typed as WHERE "Field" = :Parameter_name

warning

Parameter names may not contain any of the characters <space>`!"$%^*()+={}[]@'~#<>?/,. They may not be the same as field names or SQL reserved words. They may be the same as aliases.


tip

A useful construction for selecting records based on parts of a text field's content is to add a hidden column with "LIKE '%' || :Part_of_field || '%'" as the criterion. This will select records with an exact match. If a case-insensitive test is wanted, one solution is to use LOWER (Field_Name) as the field and LIKE LOWER ( '%' || :Part_of_field || '%' ) as the criterion. Note that the spaces in the criterion are important; if they are left out the SQL parser interprets the entire criterion as a string to be matched. In SQL mode this should be typed as LOWER ( "Field_Name" ) LIKE LOWER ( '%' || :Part_of_field || '%' ).


Parameter queries may be used as the data source for subforms, to allow the user to restrict the displayed records.

Parameter Input

The Parameter Input dialog asks the user to enter the parameter values. Enter a value for each query parameter and confirm by clicking OK or typing Enter.

The values entered by the user may consist of any characters which are allowable for the SQL for the relevant criterion; this may depend on the underlying database system.

tip

The user can use the SQL wild-card characters "%" (arbitrary string) or "_" (arbitrary single character) as part of the value to retrieve records with more complex criteria.


SQL modua

SQLk "Structured Query Language" (Kontsulta-lengoaia egituratua) esan nahi du, eta datu-base erlazionalak eguneratzeko eta kudeatzeko instrukzioak deskribatzen ditu.

LibreOffice aplikazioan, kontsulta gehienetarako, ez da beharrezkoa SQL ezagutzea, ez baita SQL koderik sartu behar. Kontsulta-diseinatzailean kontsulta bat sortzen bada, LibreOffice aplikazioak instrukzioak haiei dagozkien SQL sintaxi bihurtuko ditu automatikoki. Aktibatu/desaktibatu diseinu-ikuspegia botoiaren bidez SQL ikuspegira joanez gero, aurrez sortutako kontsulta baten SQL komandoak ikusi daitezke.

Kontsulta zuzenean SQL kodean formulatu daiteke. Kontuan izan, hala ere, sintaxi berezia erabilitako datu-basearen sistemaren araberakoa izango dela.

SQL kodea eskuz sartzen bada, Kontsulta-diseinatzailea interfaze grafikoak onartzen ez dituen SQL kontsultak sortu daitezke. Kontsulta horiek jatorrizko SQL moduan exekutatu behar dira.

By clicking the Run SQL command directly icon in the SQL view, you can formulate a query that is not processed by LibreOffice and sent directly to the database engine.