title: Using variables in Complex MySQL Query
body: <p>My MySQL Query is like this : </p>
  
  <pre><code> $myquery= "`SELECT  `year`, 
  
          sum(case when `countrycode` = '$countryone' then `values` else 0 end) AS `$countryone`,
          sum(case when `countrycode` = '$countrytwo' then `values` else 0 end) AS `$countrytwo`
  
  FROM   `$index`
  GROUP BY `year`"; 
  </code></pre>
  
  <p>This Query has to return all the values of the column values for two unique countrycodes in two different columns. </p>
  
  <p>Before using the variables. my query was like this, which returned right output. </p>
  
  <pre><code>     $myquery = "SELECT  `year`, 
  
          sum(case when `countrycode` = 'NPL' then `values` else 0 end) AS `NPL`,
          sum(case when `countrycode` = 'USA' then `values` else 0 end) AS `USA`
  
  FROM   `gainfinal`
  GROUP BY `year`
  ";
  </code></pre>
  
  <p>But after replacing the real values with the variables the Query didn't work. How can I make the first Query run well ? </p>