Title: Mysql querys help
Last modified: August 20, 2016

---

# Mysql querys help

 *  [kennyist](https://wordpress.org/support/users/kennyist/)
 * (@kennyist)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/mysql-querys-help/)
 * Hi,
 * I’m trying to do a simple sum query based on category but what ever i try does
   not work.
 * “
    $wpdb->wpfb_files = $wpdb->prefix . ‘wpfb_files’;
 * $total_hits = $wpdb->get_var( “SELECT SUM(file_hits) FROM $wpdb->wpfb_files WHERE
   file_category = 2″ );”
 * It didn’t even work without the Where.
 * How would you go about doing this?
 * thanks,
    Kennyist.
 * _[[No Bumping](http://codex.wordpress.org/Forum_Welcome#No_Bumping)]_

Viewing 1 replies (of 1 total)

 *  [Rajesh Soni](https://wordpress.org/support/users/rajeshsoni/)
 * (@rajeshsoni)
 * [13 years, 5 months ago](https://wordpress.org/support/topic/mysql-querys-help/#post-3537851)
 * Let’s first get the raw SQL for debugging…
 *     ```
       $wpdb->wpfb_files = $wpdb->prefix . 'wpfb_files';
   
       $sql = "SELECT SUM(file_hits) FROM $wpdb->wpfb_files WHERE file_category = 2" ;
   
       $total_hits = $wpdb->get_var( $sql );
   
       echo "SQL: $sql<br/>";
       ```
   
 * With the output, run the SQL query manually (eg. phpmyadmin), and see what you
   get.
 * Try replacing `SUM(file_hits)` with just `file_hits` in the query above as well.
 * Cheers!

Viewing 1 replies (of 1 total)

The topic ‘Mysql querys help’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [Rajesh Soni](https://wordpress.org/support/users/rajeshsoni/)
 * Last activity: [13 years, 5 months ago](https://wordpress.org/support/topic/mysql-querys-help/#post-3537851)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
