SQL query involving count, group by and substring
<p><a href="https://i.stack.imgur.com/LgZlP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LgZlP.png" alt="enter image description here"></a></p>

<p>I would like to group rows of this table according to dates which form the start of <code>SessionID</code> and for each day, I would like to count how many rows there are for each set of <code>ReqPhone</code> values. Each set of <code>ReqPhone</code> values will be defined by the first four digits of <code>ReqPhone</code>. In other words, I would like to know how many rows there are for <code>ReqPhone</code> starting with <code>0925</code>, <code>0927</code> and <code>0940</code>, how many rows there are for <code>ReqPhone</code> starting with <code>0979</code>, <code>0969</code> and <code>0955</code>, etc etc.</p>

<p>I have been trying all kinds of <code>group by</code> and <code>count</code> but still haven't arrived at the right query.</p>

<p>Can anybody enlighten me?</p>

<p>Update:</p>

<p>In my country, the government assigns telecoms phone numbers starting with certain digits. Therefore, if you know the starting digits, you know which telecom someone is using. I am trying to count how many messages are sent each day using each telecoms.</p>