tags:

views:

60

answers:

1

Morning Guys,

I have the following tables:

 operator(ope_id, ope_name)
 ope_shift(ope_id, shift_id, shift_date) 
 shift(shift_id, shift_start, shift_end)

here is a better view of the data http://latinunit.net/emp_shift.txt

here is the screenshot of a select statement to the tables http://img256.imageshack.us/img256/4013/opeshift.jpg

im using this code

SELECT OPE_ID, COUNT(OPE_ID) AS Total_shifts
from operator_shift
group by ope_id;

to view the current total shifts per operator and it works, BUT if there was 500 more rows it would count them all aswell, THE QUESTION is, anyone has a better way of making my database work, or how can i tell the system that those rows are a whole month, i remember i friend said something about count then devide by 30 but im not sure, what if the month isnt finished? and you want to show the emp with highest shifts to date

A: 

you need to add a where clause:

where shift_date in ('2010-04-01', '2010-04-30')

or alternately

where (shift_date >= '2010-04-01' AND shift_date < '2010-05-01')

You might need to fudge the date format to match your particular implementation.

Williham Totland
In addition, if fields are date/time stamped, and you are looking for '2010-04-30', you can either change to < '2010-05-01' OR, change the date to include 11:59:59 pm to include any time within a given date.
DRapp
Yes, that's probably a better idea; updating answer to reflect. The fields are quite clearly date fields, tho', not datetime. :)
Williham Totland
im using this codeselect ope_id, count(shift_id) as Total_shiftsfrom operator_shiftwhere ope_shift_DATE in ('01-MAR-2010','30-MAR-2010')GROUP BY OPE_ID;but it shows the wrong data, say there are 500 rows of employees shifts for different days and months, how can i count which employee in that month has done the most shifts or so
DAVID
@DAVID: As I mention, you still have to coerce your select statement into the proper types; probably using to_date('2010-04-01','yyyy-mm-dd'), or whatever date format you want. 01-MAR-2010 is just a string representation generated by your SQL shell; it won't automatically fold strings back to dates for you.
Williham Totland