title: MySQL set a variable inside CTE: "select" is fine but "set" doesn't work
body: <p>People say CTE is a view and you can't set a variable in CTE.
  But I successfully set a variable @ttl in CTE running the query below:</p>
  <pre><code>with CTE as (select @ttl:=(select sum(num) from test))
  </code></pre>
  <p>And when I run this, which I thought just another way to set a variable, I got an error:</p>
  <pre><code>with CTE as (set @ttl=(select sum(num) from test))
  </code></pre>
  <p>I'm very confused. What exactly is doable and what is not in terms of setting a variable in CTE?</p>