Dynamic query for stored procedure
Actually you don't need a dynamic query, you need a pivot query:

SELECT Nama,
SUM(CASE WHEN Motor = 'Vario' THEN 1 ELSE 0 END) as Vario,
SUM(CASE WHEN Motor = 'Beat' THEN 1 ELSE 0 END) as Beat,
SUM(CASE WHEN Motor = 'Supra' THEN 1 ELSE 0 END) as Supra,
SUM(CASE WHEN Motor = 'Megapro' THEN 1 ELSE 0 END) as Megapro
SUM(CASE WHEN Motor = 'CB150' THEN 1 ELSE 0 END) as CB150
FROM MatrixReport
GROUP BY Nama;


This query will automatically sum up whether new rows are added or not.

This is a SQL query, not an SP. You need to learn more about how to create a stored procedure. Take a look at these Stack Overflow Q &amp; As to help you in creating your first SP:


Beginners' guide to stored procedures with MySQL
Creating a Procedure MySQL
MySQL create stored procedure syntax with delimiter


You should also learn more about GROUP_CONCAT function in MySQL:


Aggregate (GROUP BY) Function Descriptions - GROUP_CONCAT
How to use GROUP_CONCAT in a CONCAT in mysql