jeudi 3 décembre 2015

Return multiple date values from a single date, perhaps using variables and a subquery?

I'm using sqlite and have created a simple timesheet for my employees, and want to output data out to analyse on how many billable hours they do in a day.

They create a single record in the timesheet file, which inserts the date the record was created (which could be any day, not necessarily monday) and the staffID belonging to the timesheet. Staff record multiple records in the timesheet_line file depending on which projects they have been working on during the week. mon, tues, wed… etc. contain the hours they have worked on a particular project.

The following are the data structures, timesheet_line is built like this to mimic the spreadsheet I currently have, but I know this makes my sql life more difficult trying to get the data out….

timesheet (tablename)
timesheetID, date, staffID

timesheet_lines (tablename)
timesheetID, customerID, projectID, charge_rate, mon, tues, wed, thurs, fri, sat, sun

So for example if a staff called Joe Kool has created a timesheet with the date 2015-12-03, I want to output the following. If its a Monday, I need it to calculate the date

2015-11-30 projectID1, customerID1, mon, staffID
2015-11-30 projectID2, customerID2, mon, staffID
2015-11-30 projectID3, customerID3, mon, staffID
2015-12-30 projectID4, customerID3, mon, staffID
2015-12-01 projectID2, customerID2, tues, staffID 
etc…..

Can someone help me with this, assuming I'm going to have to declare variables to get the dates and use a separate subquery for each day or is this data structure and sql in general not good for this kind of thing? making me think I be manipulating the raw data in my interface? Input would be good, I know how to do simple queries, but manipulating the dates is making me pull my hair out.

Aucun commentaire:

Enregistrer un commentaire