how can i take the difference of 2 date/time (in minutes)columns and get the average? i have orders received time and orders completed time for every order in every state over a period of one month. my select statement is below, but for some reason it is returning some negative values. oh and one more thing, i need to not include saturdays and sundays 12/3,4,10,11,17,18,24,25,31. any input would be greatly appreciated.
select rt_state.state_code, avg(datediff(mi,dt_orders.request_received_date,dt_orders.order_delivered_date))
from dt_orders, dt_address, rt_state
where dt_orders.address_id = dt_address.address_id and
dt_address.state_number = rt_state.state_number and
dt_orders.request_received_date between '12/1/04' and '1/1/05' and
dt_orders.order_delivered_date < '1/1/05'
group by rt_state.state_code;