Operations with calculated fields from a mysql view

Asked

Viewed 225 times

1

Good afternoon,

I have a view where there are several fields where I have several calculations, and the result of these calculations I would like to use in other fields of this same view.

An example:

    select (tab1.campo1+tab1.campo2)/tab1.campo1-1 as margem, 
margem * 100 as %margem from tab1;

Since the calculation of "%margin" is done with the result of the previous calculation.

I tried to use this way but error occurs below:

Error Code: 1054. Unknown column 'settlement commission' in 'field list'

  • How are you doing it ? Put your Query. But I could see that the column name liquidation commission does not exist. As a suggestion, avoid name fields with accents, spaces and the like.

  • Edit that title for God’s sake, it looks like you’re yelling at us.

  • Just don’t answer, boss

  • The error that appears is Error Code: 1054. Unknown column name that I use in 'field list'

  • select (tab1.campo1+tab1.campo2)/tab1.campo1-1 the margins, (tab1.campo1+tab1.campo2)/tab1.campo1-1 * 100 the %margin from tab1;

  • Yes, the view I have today is being similar. The problem is that the calculation I used as an example is much simpler than using it in the original code. I would like to use the result of one column to calculate another.

  • %margem is not a alias valid, try with percentual_margem.

  • ok, select (tab1.campo1+tab1.campo2)/tab1.campo1-1 the margins, margin * 100 the margem_percentage from tab1; Likewise it does not work

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.