{"id":1734,"date":"2017-07-18T18:37:50","date_gmt":"2017-07-18T18:37:50","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=1734"},"modified":"2025-04-04T12:42:11","modified_gmt":"2025-04-04T11:42:11","slug":"get-number-of-results","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/mysql\/queries\/select\/get-number-of-results","title":{"rendered":"Count &#8211; Get number of results"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">How many rows in a table <\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT COUNT(*) AS Count FROM tblMyTable;\n\n  $Output = 0;\n  if (count($Results) &gt; 0)\n    $Output = $Results&#91;0]&#91;'Count'];\n  \n  return($Output);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Count and Group Combined<\/h4>\n\n\n\n<p>List the number of customers in each country<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT COUNT(Id), Country FROM tblMyTable GROUP BY Country<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Adding values returned as a the total<\/h4>\n\n\n\n<p>Use SUM()<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Counting multiple things in a single query<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT \n    COUNT(*) AS TotalUsers,\n    COUNT(CASE WHEN EmailAddress != '' THEN 1 END) AS EmailAddressCount,\n    COUNT(CASE WHEN UserAcceptsMarketing = 1 THEN 1 END) AS UserAcceptsMarketingCount,\n    COUNT(CASE WHEN Options != 0 THEN 1 END) AS OptionsCount,\n    COUNT(CASE WHEN Joined > NOW() - INTERVAL 30 DAY THEN 1 END) AS JoinedInLast30DaysCount,\n    COUNT(CASE WHEN LastActive > NOW() - INTERVAL 30 DAY THEN 1 END) AS ActiveInLast30DaysCount\nFROM my_table;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How many rows in a table Count and Group Combined List the number of customers in each country Adding values returned as a the total Use SUM() Counting multiple things in a single query<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[64],"tags":[],"class_list":["post-1734","post","type-post","status-publish","format-standard","hentry","category-select"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=1734"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1734\/revisions"}],"predecessor-version":[{"id":4816,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/1734\/revisions\/4816"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=1734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=1734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=1734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}