title: What is wrong in this query ? I'm getting an error as "select is not valid at this position for this server version, expecting : '(', WITH"
body: <p>My Query</p>
  
  <p>error: <strong>select is not valid at this position for this server version, expecting : '(', WITH</strong></p>
  
  <pre><code>    set @prev="SAME";
      select `date`, `COL1` , `COL2` ,
                  if( `COL1`&gt;`COL2` and ( (@prev="SAME") or (@prev="UP") ) ) then
                      "DOWN", @prev:="DOWN"
                  else if( `COL1` &lt; `COL2` and ( (@prev="SAME") or (@prev="DOWN") ) ) then
                      "UP", @prev:="UP"
                  else
                      "SAME"
                  END IF
                  as 'sign' 
        from 
            temp;
  </code></pre>