I am trying to write a custom sql that will provide to me data related to the Magento2 EE reward points. My issue is that my queries seem to be showing 0 as the result which can not be because when I manually look at some customer’s profiles in the Magento admin and go to their reward points table I can see some customers have points.
My goal is to understand the average # of points my customers have and how many customers have at least x amount of points.
Here is my code:
$tempcon = mysqli_connect("127.0.0.1","fdghfdhg","abcdefg","foobar");
//Select Data from table
$sql = mysqli_query($tempcon, "SELECT AVG(points_balance) as avgpoints FROM magento_reward");
$sqla = mysqli_query($tempcon, "SELECT COUNT(customer_id) as customersabovefifty FROM magento_reward WHERE points_balance > 499");
$sqlb = mysqli_query($tempcon, "SELECT COUNT(customer_id) as num_customers FROM magento_reward");
$sqlrow = mysqli_fetch_assoc($sql);
$sqlarow = mysqli_fetch_assoc($sqla);
$sqlbrow = mysqli_fetch_assoc($sqlb);
$customersabovefifty = $sqlarow['customersabovefifty'];
$avgpoints = $sqlrow['avgpoints'];
$num_customers = $sqlbrow['num_customers'];
echo "<h2>REWARD POINTS</h2>
<p>Customers have an average of $avgpoints points</p>
<p>Total number of customers who have points: $num_customers</p>
<p>Number of customers who have 500 or more points: $customersabovefifty";