0

I have a chart script. To know usage I have made a mysql column named first_load. When user visits the page it draws default pie chart. So, if user load the chart by default one entry gets inserted Yes. If use enters his/her preferred data and draw the chart then query inserted No. If I would like to check how many times users loaded the chart for the first time and with user's data. Is it possible to do it in one query? Instead of selecting the table first_load where = yes and no separately and counting the row?

My intention in here to reduce the query.

I can't figure out anything except two different queries

$YesData="Yes";
$NoData="No";
$yesquerys= sprintf("SELECT first_load from 'analytics' where first_load='%s'",$mysqli_real_escape_string($conn,$YesData));
$noquerys= sprintf("SELECT first_load from 'analytics' where first_load='%s'",$mysqli_real_escape_string($conn,$NoData));
DAKSH
  • 460
  • 1
  • 5
  • 22

1 Answers1

1

I found the answer MySQL: Count occurrences of distinct values I didn't know if we can count occurrences.

So, it would be

SELECT first_load,COUNT(*) as count FROM `analytics` GROUP BY first_load ORDER BY count DESC
Community
  • 1
  • 1
DAKSH
  • 460
  • 1
  • 5
  • 22