I have four tables in my Database:
Metrics
->id
->description
Agents
->id
->name
Forms
->id
->agent_id
->campaign_id
->calldatetime
->phone
Forms_Responses
->id
->form_id
->metrics_id
->response
And one of the users asked me make a report like so:
Metric ID | Agent_name | Agent_name | Agent_name .. and so on (depends how many from db)
__________|____________|____________|______________
| | |
1 | 90% | 80% | 70%
__________|____________|____________|_______________
2 | 80% | 100% | 50%
The report scales horizontally and vertically. Horizontally by Agent_ID
To get the Horizontal scalling (Columns) I have this query
SELECT a.id, b.name FROM forms a
INNER JOIN agents b ON a.agent_id = b.id
WHERE a.calldatetime >= '2015-12-12 00:00:00'
AND a.calldatetime <= '2015-12-17 23:00:37' AND campaign_id = 22 GROUP BY agent_id ORDER BY id ASC;
I have GROUP BY agent_id
so won't have a duplicate data. However my problem is on the ROWS
. So Far I have
select form_id, metrics_id, response, remarks
from forms_responses
where form_id >= 6951 and form_id <= 6953 ORDER BY id ASC;
Don't mind the where form_id >= 6951 and form_id <= 6953
. So that should be my row? Problem is how can I link that in my columns plus the values 90%, 80%..
is based from the formula
Yes Counts / (Yes Counts + No Counts)
in the response
column of the Forms_Responses
table.
So basically this is a scoring report which get's the precentage for each agent on each metrics based on response value in the formula given.
I am doing this in Laravel PHP and will output as an excel with the format mentioned but I dunno what my queries will look like or how the processing goes or is it possbile?