I have a table (tbl_operations) with rows of where the id column values may be comma-delimited. I want to get the count of each OpId for each month. I am trying to accomplish this through pure sql, but without success.
from this view
| OpId | OpDate |
|---|---|
| 3 | 2022-01-03 |
| 5,3 | 2022-01-15 |
| 4 | 2022-01-27 |
| 5 | 2022-02-01 |
| 7 | 2022-02-09 |
| 3,2 | 2022-01-16 |
to this
| OpId | count | Month |
|---|---|---|
| 2 | 1 | 01 |
| 3 | 3 | 01 |
| 4 | 1 | 01 |
| 5 | 1 | 01 |
| 5 | 1 | 02 |
| 7 | 1 | 02 |
I am stuck here. Can someone enlighten me on how to do this with sql? If not, maybe use php to display the result?
SELECT tbl_operations.OpId,
tbl_operations.OpDate ,
COUNT(tbl_operations.OpId) AS `count`
FROM tbl_operations
WHERE MONTH(OpDate)=1
GROUP BY tbl_operations.OpId