table divide ...

Prev Next

Function Names

table divide, table divide selected rows

Description

A relational division will be made from two tables referred as dividend (numerator) and divisor (denominator). A new table called quotient will be generated.

The dividend (numerator) table contains a set of headers C = A + B where
A refers to a set of headers which are not found in the divisor (denominator), and
B refers to a set of headers which are found in the divisor (B'). The divisor table does not contain header names which are not found in the dividend table, meaning that both sets B and B' must contain the same headers. Ordering does not matter. The resulting quotient table will contain columns with headers A' which are the same headers as in set A in the dividend table. Briefly said: From the dividend table, pick all entries with common headers A, which match with all rows in the divisor table.
Function 'table divide'

Call as: procedure

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters

Parameter count

4-6

Parameters

No.TypeDescription
Opt. 1.
code
expression
:string
Expression to select rows

Applicable to function table divide selected rows only, affecting the numerator table.
Specify the conditions or rules to select the row. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

Default value: true (all rows selected)
1. / 2.
input
string Name of existing numerand (dividend) table

The table will not be modified by this function

2. / 3.
input
string Name of existing denominator (divisor) table

The table will not be modified by this function

3. / 4.
input
string Name of quotient table

This table will be created.

Opt 4. / 5.
input
table columns Numerator columns

Select the columns in the dividend (numerator) table to be used for the actual division process. This feature drops the need for extracting a dedicated dividend table with the chosen columns to be used for division process.

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Any number of header names and column numbers may be specified

Opt 5. / 6.
input
table columns Categorization columns

Specifing categorization columnns allows to do multiple division runs with different categories as specified as set of 1 or more headers this parameter. As an example if a country name is specified, then the division process will be repeated for all countries, and the quotient table contains an additional column at the left listing the country name in one of the examples shown below.

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Any number of header names and column numbers may be specified

Simple example

The following example does actually scan the numerator table for common parents of both children called Maria and Sabine (note: Age must also match). Actually, function divide answers the question on: "Find all parents (father and mother) who have two children, one called Maria and 4 years old, and the other one called Sabine, 2 years old. Two parents will be identified.

Code
       table initialize( numerator,
               { { Father,    Mother,   Child,   Age },
                 { Franz,     Helga,    Harald,    5 },
                 { Franz,     Helga,    Maria,     4 }, // No match - different parents
                 { Franz,     Ursula,   Sabine,    2 }, // "
                 { Moritz,    Melanie,  Gertrud,   7 },
                 { Moritz,    Melanie,  Maria,     4 }, // Match
                 { Moritz,    Melanie,  Sabine,    2 }, // Match
                 { Peter,     Lisa,     Robert,    9 },
                 { Johann,    Lisa,     Maria,     4 }, // Match
                 { Johann,    Lisa,     Sabine,    2 }  // Match
               } );

       table initialize( denominator,
               { { Child,   Age },
                 { Maria,     4 },
                 { Sabine,    2 } } );

       table divide( numerator, denominator, quotient );

       table list( quotient );
Two parent couples have been identified
    0 : Father | Mother
    1 : Moritz | Melanie
    2 : Johann | Lisa   

Try it yourself: Open LIB_Function_table_divide.b4p in B4P_Examples.zip. Decompress before use.

Example with categorization by country

The following example shows the categorization feature:

Code
       table initialize( numerator,
               { { Father,    Mother,   Child,   Age },
                 { Franz,     Helga,    Harald,    5 },
                 { Franz,     Helga,    Maria,     4 }, // No match - different parents
                 { Franz,     Ursula,   Sabine,    2 }, // "
                 { Moritz,    Melanie,  Gertrud,   7 },
                 { Moritz,    Melanie,  Maria,     4 }, // Match
                 { Moritz,    Melanie,  Sabine,    2 }, // Match
                 { Peter,     Lisa,     Robert,    9 },
                 { Johann,    Lisa,     Maria,     4 }, // Match
                 { Johann,    Lisa,     Sabine,    2 }  // Match
               } );

       table initialize( 2 countries, { Country, Austria, Germany } ); // Add countries for each row
       table multiply( 2 countries, numerator, 0 );
       table sort rows ( numerator, Country );
       table list ( numerator );

       table initialize( denominator,
               { { Child,   Age },
                 { Maria,     4 },
                 { Sabine,    2 } } );

       table divide( numerator, denominator, quotient, { Father, Mother, Child, Age }, Country );

       table list( quotient );
Two parent couples from each country have been identified
    0 : Country | Father | Mother  | Child   | Age
    1 : Austria | Franz  | Helga   | Harald  | 5  
    2 : Austria | Franz  | Helga   | Maria   | 4  
    3 : Austria | Franz  | Ursula  | Sabine  | 2  
    4 : Austria | Moritz | Melanie | Gertrud | 7  
    5 : Austria | Moritz | Melanie | Maria   | 4  
    6 : Austria | Moritz | Melanie | Sabine  | 2  
    7 : Austria | Peter  | Lisa    | Robert  | 9  
    8 : Austria | Johann | Lisa    | Maria   | 4  
    9 : Austria | Johann | Lisa    | Sabine  | 2  
   10 : Germany | Moritz | Melanie | Maria   | 4  
   11 : Germany | Franz  | Ursula  | Sabine  | 2  
   12 : Germany | Moritz | Melanie | Sabine  | 2  
   13 : Germany | Franz  | Helga   | Maria   | 4  
   14 : Germany | Peter  | Lisa    | Robert  | 9  
   15 : Germany | Moritz | Melanie | Gertrud | 7  
   16 : Germany | Johann | Lisa    | Maria   | 4  
   17 : Germany | Franz  | Helga   | Harald  | 5  
   18 : Germany | Johann | Lisa    | Sabine  | 2  

    0 : Country | Father | Mother
    1 : Austria | Moritz | Melanie
    2 : Austria | Johann | Lisa   
    3 : Germany | Moritz | Melanie
    4 : Germany | Johann | Lisa   

Try it yourself: Open LIB_Function_table_divide_01.b4p in B4P_Examples.zip. Decompress before use.

See also

table multiply