title: In Wordpress, how do I display sum from a column of a MySQL table in a page?
body: <p>Say my database table is called "mytable", and it has the following data :</p>
  
  <pre><code>Id            Name             Category          Points
  -----------------------------------------------------------
  1             ABC               Good              40
  2             DEF               Good              20
  3             GHI               Bad               10
  4             JKL               Good              30
  5             MNO               Bad               20
  </code></pre>
  
  <p>And in my Wordpress page, I want to display the following:</p>
  
  <pre><code>Total Points for Good = 90
  Total Points for Bad  = 30
  </code></pre>
  
  <p>Please help</p>
  
  <p>Update I tried using the code given by @user3405706</p>
  
  <p>in my function.php to use as Shortcode</p>
  
  <pre><code>      function sum_good() {
  global $wpdb; 
  $result_good = $wpdb-&gt;get_results("Select sum(points) as good_points from mytable where category='Good'");
  
          $haha= "Total Points for Good =".$result_good['good_points'];
          return $haha;
          /// do same for other category
          }
      add_shortcode('sumgood', 'sum_good');
  </code></pre>
  
  <p>But the shortcode display only :</p>
  
  <pre><code>Total Points for Good = 
  </code></pre>
  
  <p>What am I doing wrong</p>