I am trying the following
global $wpdb;
$sum = $wpdb->get_var("select sum(first), sum(second) from table where id > 1");
I am unable to get the values from each request. I have tried
echo $test->sum(first);
I have tried to change the sql statement to include AS
$sum = $wpdb->get_var("select sum(first) as firstRequest, sum(second) as secondRequestfrom table where id > 1");
echo $test['firstRequest'];
I have tried a foreach
statement
foreach($test as $tester){
echo $tester['sum(first')];
}
and
foreach($test as $tester){
echo $tester['firstRequest'];
}
How can I retrieve the sum of multiple rows from a single get_var
statement? If not possible, and I need the sum of 5 different rows, would I have to create 5 separate get_var
statements? Would this decrease the querying speed, if so, is it even noticeable?
get_results
instead?