Editor Instance sql SUM function addition

Editor Instance sql SUM function addition

wbyerswbyers Posts: 48Questions: 12Answers: 1
edited January 2018 in Free community support

is it possible using the an Editor field instance to add several sums and use that as a field, provided you set it to false? Specifcally can I add the sums of several database fields together and use the total as a field. I know we can use 1 mysql function, does editor support something like SUM(field)+SUM(field2) ?

This question has accepted answers - jump to:

Answers

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    To clarify I'm trying to add a field from one table to a field from a joined table. Is that doable using the editor php library?

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin

    The easiest way of doing this is actually to use a renderer on the client-side.

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    Can that be done using the server side Editor php library? I'm just fine on the actual table.

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Yes, as of Editor 1.7 you can use SQL functions in the Field statements, as long as it is set to read only - e.g.:

    Field::inst( 'SUM(field1, field2)' )->set( false )
    

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    can the sum be with a field from the first table and then a joined table field?

  • allanallan Posts: 63,457Questions: 1Answers: 10,465 Site admin
    Answer ✓

    Yes - just like you would in SQL add the table qualifier.

    Make sure you use the leftJoin() method to do the join as well.

    Allan

  • wbyerswbyers Posts: 48Questions: 12Answers: 1

    thank you

This discussion has been closed.