MySQL to get the count of rows for each worker with specific dates and jobs -


i have database of workers , assigned work items. want create report using mysql show count of how many work items under jobs , within date ranges each worker has. resulting data this:

            today          tomorrow        next year worker | job1 job2 job3 | job1 job2 job3 | job1 job2 job3  bob    |  4    0   1    | 1    2    0    | 5    10   3 

i have 1 table following relevant fields: worker, date, jobtype, workitem

each worker has multiple entries under same name, bob have multiple workitems assigned him, this:

bob | 07/27/2011 | sandblasting | workitem001 bob | 08/30/2011 | mowing | workitem001 bob | 08/30/2011 | driving | workitem002 

workitems can assigned multiple jobtypes.

i wrote confusing loops multiple queries, ideally want write single, complex query accomplish this. possible?

overview each day:

select worker, date, job, count(*) count workitems group worker, date, job 

overview month/year:

select worker, month(date) month, job, count(*) count workitems group worker, month, job 

that's it. table format little different in mysql cannot put values columns (job1, job2, job3 in example), possible e.g. ms access' cross query. can export data mysql above queries , e.g. use ms excel contingency tables produce output want.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -