tags:

views:

17

answers:

1

I have this kinda query:

SELECT 
  IF(daycode=1,(SELECT...),(SELECT...)) AS weekavg,
  (SELLOFF1 / weekavg) AS procent
FROM .....

it tells me: Unknown column 'weekavg' in 'field list', this happens after I've added the divide, prior to that worked ok.

+1  A: 

You can use a sub-query:

SELECT (selloff1 / weekavg) AS procent
FROM (
  SELECT 
    selloff1, IF(daycode=1,(SELECT...),(SELECT...)) AS weekavg
  FROM ...
)
Peter Lang
One more thing, how can I add this to the end of your query `where procent NOT BETWEEN (100-25) AND (100+25)` it gives error.
Pentium10
Unknown column 'd.procent' in 'where clause', where `d` was the alias for the derived table.
Pentium10
I am after to get results that `varied 25%`, also I am after an efficient way.
Pentium10
@Pentium10: You would have to add another level of sub-queries or use `(selloff1 / weekavg)` instead of the alias.
Peter Lang