title: SQL Query to retrieve data on 2016 Presidential Election demographics, google trends, and votes
body: <p><a href="https://i.stack.imgur.com/lZUqN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lZUqN.png" alt="Query 1" /></a></p>
  <p>I tried - but it does not present the correct order</p>
  <p><code>SELECT * FROM demographics d INNER JOIN votes v ON d.CountyID = v.CountyID GROUP BY d.state ORDER BY republican DESC</code></p>
  <p><a href="https://i.stack.imgur.com/BBX5r.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BBX5r.png" alt="Query 2" /></a></p>
  <p>I tried - but there is a syntax error near line 4 and I cannot determine how to join both the google trends, demographics, and votes tables while successfully referencing the google search_trump to a national average since national average doesn't exist and must be calculated</p>
  <pre><code>SELECT 
      d.State
      , SUM(v.Democrats) AS total_votes_democrat
      , SUM(v.Republican) AS total_votes_republican
      , SUM(v.Others) AS total_votes_other
      , SUM(d.Total_Population) AS total_population
      , AVG(d.Percent_White) AS avg_per_white
      , AVG(d.Percent_Black) AS avg_per_black
      , AVG(d.Percent_Asian) AS avg_per_asian
      , AVG(d.PerCapita_Income) AS avg_inc_per_capita
      , AVG(d.Median_Rent) AS avg_median_rent 
  FROM 
      demographics d INNER JOIN votes v ON v.CountyID = d.CountyID 
      INNER JOIN googletrends g ON g.State = d.State 
  WHERE g.GoogleSearch_Trump &gt; SUM(GoogleSearch_Trump, GoogleSearch_Clinton)/2
  </code></pre>
  <p>TABLES INCLUDE: demographics, google trends, votes</p>
  <p>COLUMNS INCLUDE:</p>
  <p>Demographics - (CountyID, Name, State, total_population, percent_white, percent_black, percent_asian, percent_hispanic, per capita_income, median_rent, median_age)</p>
  <p>Googletrends - (state, google search_trump, google search_clinton)</p>
  <p>Votes - (CountyID, democrats, republican, others)</p>