Previous Page Table of Contents Next Page


6. DATABASES AND DATA MANAGEMENT (Contd.)

6.5 REPORTS FROM THE DATA BASE

A database system includes a number of pre-prepared reports, which can be automatically produced. The reports are the output from the sampling programme. In this section, we shall deal only with one type of report, namely the reports specifying the quantitative content of the database, that is the number of records of each type, who collected the data where and when (the administrative reports). The database reports for wider distribution, the primary output from the database will be dealt with in Section 6.8.

The administrative reports are mainly for the internal evaluation of the sampling programme. They are used to modify the sampling programme in order to make the best use of the limited resources available. Furthermore, the administrative reports can be used to compute the average costs of samples for the different fleets at different locations, when combined with the accounting records of the sampling programme. One could include the costs of sampling in the catch effort database, but the costs of sampling should be kept distinct from the fisheries statistics.

When an interview form is filled in, it will contain information on who (the enumerator) filled in the form and who entered the data into the computer. This information is needed for the subsequent validation (and, if applicable, correction) of data.

The database will thus be able to produce tables, which summarises the activities of all enumerators and encoders. The database contains a look-up table with all the particulars of the entire staff of the sampling programme. A person becomes an authorised staff member of the data collection programme, by being included in the table of staff members. Only authorised persons can enter data in the database.

Apart from reports on the staff activities, the administrative reports comprises summaries of data collection activities, such as:

  1. Number of interviews by fleet, month, province (or landing place).

  2. Number of frame survey samples by province (or homeport) by month and fleet.

  3. Number of vessel registrations by province (or homeport) by months and fleet.

  4. Number of species composition samples by commercial group, fleet, month, province (or landing place).

  5. Number of biological samples (e.g. length frequency samples).

To make the full use of these samples for the improvement of stratification, the administrative reports should also indicate the weight and value of landings represented by the samples.

6.6 SQL (STRUCTURED QUERY LANGUAGE)

The user who wants to apply the data for non-standard (e.g. research) purposes is not satisfied with the pre-prepared reports. She/he will need the data structured a specific way, to allow for some specific processing. It is the experience of the author that in practice the database system never contains all the reports you need. It is more or less impossible to predict every request for a report from every user. The skill to extract of data from the database is the primary skill you need to make full use of the database. Although this skill is often considered restricted to “computer experts” it is recommended that also other users acquire the basic skill to extract data.

In order to do this, the database user must master the SQL language. This is the tool by which you can extract data from a database, and by which you can do the first processing of the data, such as summation, grouping, calculating averages, etc. The part of SQL dealt with here, deals only with the creation of “Queries” (SQL contains a lot more than the query).

This section is by no means an attempt to teach the universal database language, SQL. The interested reader is referred to one of the many textbooks on SQL (e.g. Stephens et al. 1997). This section is to inform the reader with no or little background in database theory about the existence of SQL, and to give brief some idea of what the SQL is.

A query in SQL is most often constructed the following way (SQL-words are in capitals):

SELECT 
 (The columns you want in the table)
FROM 
 Where the data should come from, (from one or several Tables)
WHERE 
 (The subset of data, say, only data from 1 Oct 1996 to 30 Sep 1997)

You may furthermore add: “GROUP BY” in case you want to sum or average over a group, say, a fleet.

One good reason for knowing some SQL is that it puts the user in a position to define exactly which data she/he wants. Should the knowledge of SQL and the database not be sufficient to complete the job, the user will be competent to complete the job with a little help from a “computer expert”.

We illustrate the SQL by a simple (hypothetical) fisheries database with only three tables. One table is an input data table “Landings” and there are two look-up tables “L_Species” and “L_Vessel_Register” (see Table 6.6.1).

Table 6.6.1 Tables of hypothetical data for demonstrating a fisheries database.

Table: Landings

Landings_IDSpecies_CodeLandings_KgVessel_CodeDate_Of_Landing
1SAR2HP1711-Jan-98
2TPR3HP1711-Jan-98
3SCR1HP1712-Jan-98
4LOB4HP1712-Jan-98
5GRP3QN1912-Jan-98
6SAR6QN1913-Jan-98
7KMC11HP8313-Jan-98
8TPR2HP8315-Jan-98
9TBR2QN0115-Jan-98
10SQU3QN0115-Jan-98
11LOB5QN0116-Jan-98
12CUF1QN0116-Jan-98
13GCL7HP1716-Jan-98
14CRP15HP1717-Jan-98
15LOB5HP1717-Jan-98
16LOB8HP8317-Jan-98
17LOB2HP8317-Jan-98
18WSH4HP8319-Jan-98
19CUF2QN0118-Jan-98
20MAC6QN0118-Jan-98
21SAR8HP1719-Jan-98
22WSH5HP1719-Jan-98
23TRV10HP8319-Jan-98
28TPR5HP8319-Jan-98
29CUF11QN0120-Jan-98
30TBR8QN0120-Jan-98
31TRV12QN0120-Jan-98
32SCR4HP8320-Jan-98
33SCR10HP1720-Jan-98

Table: L_Species

Species_CodeName_of_SpeciesPrice_Per_Kg
CUFCuttlefish4
GCLGiant Clam15
GRPGrouper21
KMCKing Mackerel17
LOBLobster40
RSNRed Snapper10
SARSardine6
SCRSwimming Crab23
SNLSnail12
SQUSquid14
TBRThreadfinned bream5
TPRTiger Prawn32
TRVTrevally3
TUNYellowfin Tuna11
WSHWhite Shrimp23

Table: L_Vessel_Register

Vessel_CodeName_of_Vessel
HP17Viet Nam Star
HP83Bien Dong
QN01Halong 408B
QN19Bac Bo explorer

The table “Landings” contains the total landings (“Landings_Kg”) by species and by vessel (“Species_Code” and “Vessel_Code”, respectively) and the date landed (“Date_Of_Landing”). The look-up table “L-Species” converts the 15 species codes of this example, into 15 species names (“Name_Of_Species”) and it contains the price per kg, which is thus assumed to remain constant. Eventually, there is the vessel register, “L_Vessel_Register”, which in this hypothetical example contains only 4 vessels.

The Landings-table has a key field, “Landings_ID”, which is a unique number for each record. This unique number is used to secure the integrity of data, For example, landings_ID 16 and 17 are both with LOB (Lobster) landed by vessel HP83 on the 17th January 1998. The reason could be that two different merchants bought lobsters from HP83 on the 17th January.

The “Landings_ID” values are arbitrary numbers created by the database system. Had the “Landings_ID” not been there, there would have been two records with the same keys (“Species_Code”, “Vessel_Code” and “Date_of_Landing”) and a relational database would not accept it.

Table 6.6.2.a. Queries of hypothetical demonstration fisheries database (presented in SQL language and resulting table).

Query 1: (SQL)

SELECT

Landings.Species_Code,
Landings.Landings_Kg,
Landings.Date_Of_Landing
FROM
Landings;

Query 2: (SQL)
SELECT
Landings.Species_Code,
Landings.Landings_Kg,
Landings.Date_Of_Landing
FROM Landings
WHERE
Landings.Species_Code = ‘LOB’;

Query 3: (SQL)
SELECT
Landings.Species_Code,
Landings.Landings_Kg,
Landings.Date_Of_Landing
FROM
Landings
WHERE
Landings.Species_Code IN

(‘LOB’,‘TPR’,‘SCR’,‘WSH’)
AND
Landings.Date_Of)_Landing >
#1/12/98#;

Query 1

Species_CodeLandings_KgDate_Of_Landing
SAR211-Jan-98
TPR311-Jan-98
SCR112-Jan-98
LOB412-Jan-98
GRP312-Jan-98
SAR613-Jan-98
KMC1113-Jan-98
TPR215-Jan-98
TBR215-Jan-98
SQU315-Jan-98
LOB516-Jan-98
CUF116-Jan-98
GCL716-Jan-98
SCR1517-Jan-98
LOB517-Jan-98
LOB817-Jan-98
LOB217-Jan-98
WSH419-Jan-98
CUF218-Jan-98
KMC618-Jan-98
SAR819-Jan-98
WSH519-Jan-98
TRV1019-Jan-98
TPR519-Jan-98
CUF1120-Jan-98
TBR820-Jan-98
TRV1220-Jan-98
SCR420-Jan-98
SCR1020-Jan-98

Query 2:

Species_CodeLandings_KgDate_Of_Landing
LOB412-Jan-98
LOB516-Jan-98
LOB517-Jan-98
LOB817-Jan-98
LOB217-Jan-98

Query 3

Species_CodeLandings_KgDate_Of Landing
TPR215-Jan-98
LOB516-Jan-98
SCR1517-Jan-98
LOB517-Jan-98
LOB817-Jan-98
LOB217-Jan-98
WSH419-Jan-98
WSH519-Jan-98
TPR519-Jan-98
SCR420-Jan-98
SCR1020-Jan-98

Query 4: (SQL)
SELECT
Landings.Species_Code,
L_Species.Name_of_Species,
Landings.Landings_Kg,
Landings.Date_Of_Landing
FROM
L_Species
INNER JOIN Landings
WHERE
Landings.Species_Code IN
(‘LOB’,‘TPR’,‘SCR’,‘WSH’)
AND Landings.Date_Of_Landing
> #1/12/98#;

Query 4

Species_CodeName_of_SpeciesLandings KgDate Landing
SCRSwimming Crab1517-Jan-98
SCRSwimming Crab420-Jan-98
SCRSwimming Crab1020-Jan-98
LOBLobster516-Jan-98
LOBLobster517-Jan-98
LOBLobster817-Jan-98
LOBLobster217-Jan-98
WSHWhite Shrimp419-Jan-98
WSHWhite Shrimp519-Jan-98
TPRTiger Prawn215-Jan-98
TPRTiger Prawn519-Jan-98

Note that “IN” (Queries 3 and 4) is used to express the condition that a field value belongs to a pre-specified set of values. Note further the character “#” is used to signal that numerical characters refer to a date.

Query 5 (see Table 6.6.2.b) extends and modifies Query 4. It illustrates the calculations and the “AS”-command. The species code has been removed, and the price per kg has been added. The query also makes a calculation, namely the value of the landings “Landings.Landings_Kg*L_Species.Price_Per_Kg AS Value”. The “AS” command is used to give a new name to a variable. Note the expression “INNER JOIN .... ON ....” in Query 5, which links the records with the same species code in two tables.

Query 6 (see Table 6.6.2.b) extends Query 5. It joins Query 5 with the vessel register and adds the columns with the vessel codes.

Query 7 (see Table 6.6.2.c) simplifies Query 6, to facilitate the introduction of the concepts in Query 8.

Query 8 (see Table 6.6.2.c) extends Query 7. It illustrates the “GROUP BY”-command and the “SUM”-function. It groups the records by vessel, and computes the sum for each vessel.

Query 9 (see Table 6.6.2.c) extracts data from another query (Query 8), not from the tables. It computes the sum of all vessels. This works because each query creates its own table.

This example of SQL represents only a small fraction of the SQL commands and functions. The commands presented here are not given a comprehensive explanation. It is hoped, however, that the reader has been given the impression that SQL is a very powerful tool for data manipulation. To be able to utilise a relational database fully, an advanced user must master SQL.

Table 6.6.2.b. Queries of hypothetical demonstration fisheries database (presented in SQL language and resulting table). Continued.

Query 5: (SQL)

SELECT
L_Species.Name_of_Species,
Landings.Landings_Kg,
Landings.Date_Of_Landing,
L_Species.Price_Per_Kg,
Landings.Landings_Kg*L_Species.Price_Per_Kg
AS [Value]
FROM L_Species
INNER JOIN Landings
ON Landings.Species_Code =
L_Species.Species_Code
WHERE Landings. Species_Code IN
(‘LOB’,‘TPR’,‘SCR’,‘WSH’)
AND Landings. Date_Of_Landing>#1/12/98#;

Query 5

Name_of_SpeciesLandings_KgDate_Of_LandingPrice_Per_KgValue
Swimming Crab1517-Jan-9823345
Swimming Crab420-Jan-982392
Swimming Crab1020-jan-9823230
Lobster516-Jan-9840200
Lobster517-Jan-9840200
Lobster817-Jan-9840320
Lobster217-Jan-984080
White Shrimp419-Jan-982392
White Shrimp519-Jan-9823115
Tiger Prawn215-Jan-983264
Tiger Prawn519-Jan-9832160

Query 6: (SQL)
SELECT
L_Species.Name_of_Species, Landings.Landings_Kg,
Landings.Date_Of_Landing,L_Species.Price_Per_Kg,
Landings.Landings_Kg*L_Species.Price_Per_Kg AS [Value],
Landings.Vessel_Code
FROM L_Vessel_Register
INNER JOIN (L_Species
INNER JOIN Landings
ON Landings. Species_Code = L_Species. Species_Code)
ON L_Vessel_Register.Vessel_Code = Landings.Vessel_Code
WHERE Landings.Species_Code IN (‘LOB’, ‘TPR’, ‘SCR’,‘WSH’)
AND Landings.Date_Of_Landing>#1/12/98#;

Query 6

Name_of_SpeciesLandings_KgDate_Of_LandingPrice_Per_KgValueVessel_Code
Tiger Prawn215-Jan-983264HP83
Lobster817-Jan-9840320HP83
Lobster217-Jan-984080HP83
White Shrimp419-Jan-982392HP83
Tiger Prawn519-Jan-9832160HP83
Swimming Crab420-Jan-982392HP83
Swimming Crab1517-Jan-9823345HP17
Lobster517-Jan-9840200HP17
White Shrimp519-Jan-9823115HP17
Swimming Crab1020-Jan-9823230HP17
Lobster516-Jan-9840200QN01

Table 6.6.2.c. Queries of hypothetical demonstration fisheries database (presented in SQL language and resulting table).

Query 7: (SQL)
SELECT

Landings.Landings_Kg,
Landings.Landings_Kg*L_Species.Price_Per_Kg AS[Value],
Landings.Vessel_Code
FROM L_Vessel_Register
INNER JOIN (L_Species
INNER JOIN Landings
ON Landings.Species_Code = L_Species.Species_Code)
ON L_Vessel_Register.Vessel_Code = Landings.Vessel_Code;

Query 7

Landings_KgValueVessel_Code
212HP17
396HP17
123HP17
4160HP17
363QN19
636QN19
11187HP83
264HP83
210QN01
342QN01
5200QN01
14QN01
7105HP17
15345HP17
5200HP17
8320HP83
280HP83
492HP83
28QN01
6102QN01
848HP17
5115HP17
1030HP83
5160HP83
1144QN01
840QN01
1236QN01
492HP83
10230HP17

Query 8: (SQL)
SELECT
Landings.Vessel_Code,
SUM(Landings.Landings_Kg) AS [Total Kg landed],
SUM(Landings.Landings_Kg*L_Species.Price_Per_Kg) AS [Total Value]
FROM L_Vessel_Register
INNER JOIN (L_Species
INNER JOIN Landings
ON Landings.Species_Code = L_Species.Species_Code)
ON L_Vessel_Register.Vessel_Code = Landings.Vessel_Code

GROUP BY Landings.Vessel_Code;

Query 8

Vessel_Co deTotal Kg landedTotal Value
HP17601334
HP83461025
QN0150486
QN19999

Query 9:(SQL)
SELECT

               Sum([Query_8].[Total Kg landed]) AS [Sum Kg landed],
Sum ([Query_8].[Total Value]) AS [Sum of Value],
Count(*) AS [Count Samples]

FROM Query_8;

Query 9

Sum Kg landedSum of ValueCount Samples
16529444


Previous Page Top of Page Next Page