Multiple Row and Column via Count Statements
<p>So I intend to Query data for a couple of charts in MySQL,
The data for the charts come from the same table, but work for multiple Time ranges. So group by doesn't work.</p>

<p>The Date itself I want in the format</p>

<pre><code>Total   Oranges  Mangoes  Bananas  Tomatoes
----------------------------------------------
19       5        6          7        1
24       3        7          2        12
14       3        4          5        2
20       5        7          6        2
</code></pre>

<p>Now, I can get the Initial row using either</p>

<pre><code>SELECT 
sum(CASE WHEN Some_Criteria and (created between '2016-03-28' AND '2016-03-29')) THEN 1 ELSE 0 END ) Total , 
sum(CASE WHEN Some_Other_Criteria  and (created between '2016-03-28' AND '2016-03-29')) THEN 1 ELSE 0 END ) Oranges
...
from SomeTable.Table1
left join OtherTable ON SomeId = OtherId
</code></pre>

<p>OR via</p>

<pre><code>SELECT
(SELECT count(distinct Field) FROM from SomeTable.Table1 left join OtherTable ON SomeId = OtherId WHERE SomeCriteria and (DateRange)) AS Total
(SELECT count(distinct Field) FROM from SomeTable.Table1 left join OtherTable ON SomeId = OtherId WHERE SomeCriteria and (DateRange)) AS Oranges
...
</code></pre>

<p>Getting it in the same row would be easy as I just use the above method, but what if I want the data to be in multiple rows but based on the different date ranges?</p>