0

Subtracting one record from another within the same table limited to a field

I have designed a database but need support on the following:

* within the same table

* subtract the current record from the last record

* but only from matching fields in the first column

for example:

Table

Field 1        Field 2    Field 3

Vehicle       Cost        Difference from last Vehicle (Car) Cost

Car              $100      0

Car              $150      $50

Truck           N/A

Bicycle        N/A

Car              $350       $200 

 

I found this in the Help Line but it subtracts the last field without differentiating by the first column

let me := this;
'spend' - last((select 'TableName' where number(_id) < number(me._id)) order by number(_id)).'spend'

 

Gruss aus Amerika.  Ich wunsche euch einen guten Rutsch ins neue Jahr.

4 Antworten

null
    • Fred
    • vor 1 Monat
    • Gemeldet - anzeigen

    You can try:

    let me := this;
    'spend' - last((select 'TableName' where Field1 = me.Field1 and number(_id) < number(me._id)orderby _id)).'spend'
    
      • Mike.2
      • vor 1 Monat
      • Gemeldet - anzeigen

       danke. Ich probiere es

      • Mike.2
      • vor 1 Monat
      • Gemeldet - anzeigen

       Ich habe das probiert, leider nicht geklappt.  Ich denke weil es ein Subtable ist.   Gibt es eine Training Webseite wo man diese Programmiering selber lernen und herstellen kann.

      • Fred
      • vor 1 Monat
      • Gemeldet - anzeigen

      What is a subtable? Can you post a sample DB? or be more specific about the fields you want to use.