Select more than one row inside sub query or evade sub query
<p>I would like to know how to realize query which selects sum of time column grouped by clientid column WHERE clause is divided by months and department from the same table: </p>

<p>table is the following: </p>

<p><a href="https://i.stack.imgur.com/A2210.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A2210.jpg" alt="enter image description here"></a></p>

<p>The goal here is to have final result like the following: </p>

<p><strong>result 1.0</strong></p>

<pre><code>------------------------------
clientid | december| february
------------------------------
1        | 2:20    | 4:00
------------------------------
2        | 4:00    | 7:00
------------------------------ 
</code></pre>

<p>Result will be displayed in the following manner: </p>

<pre><code>&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Clientes&lt;/th&gt;
      &lt;th&gt;January&lt;/th&gt;
      &lt;th&gt;February&lt;/th&gt;                                                         
    &lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;?php foreach($stmt as $row)
{   
echo"
&lt;tr&gt;
  &lt;td&gt;".$row['clientid']."&lt;/td&gt;
  &lt;td&gt;".$row['january']."&lt;/td&gt;
  &lt;td&gt;".$row['february']."&lt;/td&gt;                               
&lt;/tr&gt;"; }; ?&gt;              
&lt;/tbody&gt;
&lt;/table&gt;  
</code></pre>

<p>In the following case scenario of query: </p>

<pre><code>SELECT t.clientid, t.department, 
                        (SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time` ) ) ) FROM time_management WHERE YEAR(date)='$year' AND MONTH(date)= 12 AND department = '$department' GROUP by clientid  ) as january,
                        (SELECT SEC_TO_TIME( SUM( TIME_TO_SEC( `time` ) ) ) FROM time_management WHERE YEAR(date)='$year' AND MONTH(date)= 2 AND department = '$department' GROUP by clientid ) as february
                        FROM time_management t WHERE t.department = '$department' GROUP by t.clientid
</code></pre>

<p>I get error: <strong>SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row</strong></p>

<p>Since the sub query's are returning more than one row. </p>

<p>Without GROUP BY inside the sub query's the result is the following: </p>

<pre><code>1   06:20:00    11:00:00                                            
2   06:20:00    11:00:00
</code></pre>

<p>So my question is how to structure the query in order to get the desired result showed in <strong>result 1.0</strong></p>

<p>Any help will be very welcome. Thank you!</p>