记入销售报告归档时间
Credit for sales report filing time
我有两个 date_time
字段。第一个是销售 date_time,第二个是 date_time 提交销售报告。
为了让销售人员获得信用,销售报告必须在销售完成后的当天午夜之前提交。
我目前正在计算差异,并且知道任何超过 24 小时的时间都可能不在合格时间段内。此外,有时会在 date_time 销售之前提交销售报告。
我搜索了以前的答案,没有找到任何类似的内容。
你需要这样的东西:
select to_char(report_time, 'mm/dd/yyyy hh24:mi:ss') report_time,
to_char(sales_time, 'mm/dd/yyyy hh24:mi:ss') sales_time,
round((report_time - sales_time) * 24, 6) diff_in_hours,
case when report_time < trunc(sales_time) + 2 then 'Y' else 'N' end decision
from sales
函数 trunc()
从 sales_time 中减少了小时、分钟和秒。例如日期 01/15/2015 11:59:00
它 returns 01/15/2015 00:00:00
。
接下来我们将 2 天添加到此结果。 Report_date 必须低于此值。所以:
report_time < trunc(sales_time) + 2
使用示例数据进行测试:
with sales as (select
to_date('01/15/2015 11:59:00', 'mm/dd/yyyy hh24:mi:ss') report_time,
to_date('01/15/2015 11:45:00', 'mm/dd/yyyy hh24:mi:ss') sales_time from dual
union all select
to_date('01/16/2015 23:59:00', 'mm/dd/yyyy hh24:mi:ss'),
to_date('01/15/2015 12:45:00', 'mm/dd/yyyy hh24:mi:ss') from dual
union all select
to_date('01/17/2015 00:00:01', 'mm/dd/yyyy hh24:mi:ss'),
to_date('01/15/2015 23:59:00', 'mm/dd/yyyy hh24:mi:ss') from dual)
select to_char(report_time, 'mm/dd/yyyy hh24:mi:ss') report_time,
to_char(sales_time, 'mm/dd/yyyy hh24:mi:ss') sales_time,
round((report_time - sales_time) * 24, 6) diff_in_hours,
case when report_time < trunc(sales_time) + 2 then 'Y' else 'N' end decision
from sales
输出:
REPORT_TIME SALES_TIME DIFF_IN_HOURS DECISION
------------------- ------------------- ------------- --------
01/15/2015 11:59:00 01/15/2015 11:45:00 0,233333 Y
01/16/2015 23:59:00 01/15/2015 12:45:00 35,233333 Y
01/17/2015 00:00:01 01/15/2015 23:59:00 24,016944 N
我有两个 date_time
字段。第一个是销售 date_time,第二个是 date_time 提交销售报告。
为了让销售人员获得信用,销售报告必须在销售完成后的当天午夜之前提交。
我目前正在计算差异,并且知道任何超过 24 小时的时间都可能不在合格时间段内。此外,有时会在 date_time 销售之前提交销售报告。
我搜索了以前的答案,没有找到任何类似的内容。
你需要这样的东西:
select to_char(report_time, 'mm/dd/yyyy hh24:mi:ss') report_time,
to_char(sales_time, 'mm/dd/yyyy hh24:mi:ss') sales_time,
round((report_time - sales_time) * 24, 6) diff_in_hours,
case when report_time < trunc(sales_time) + 2 then 'Y' else 'N' end decision
from sales
函数 trunc()
从 sales_time 中减少了小时、分钟和秒。例如日期 01/15/2015 11:59:00
它 returns 01/15/2015 00:00:00
。
接下来我们将 2 天添加到此结果。 Report_date 必须低于此值。所以:
report_time < trunc(sales_time) + 2
使用示例数据进行测试:
with sales as (select
to_date('01/15/2015 11:59:00', 'mm/dd/yyyy hh24:mi:ss') report_time,
to_date('01/15/2015 11:45:00', 'mm/dd/yyyy hh24:mi:ss') sales_time from dual
union all select
to_date('01/16/2015 23:59:00', 'mm/dd/yyyy hh24:mi:ss'),
to_date('01/15/2015 12:45:00', 'mm/dd/yyyy hh24:mi:ss') from dual
union all select
to_date('01/17/2015 00:00:01', 'mm/dd/yyyy hh24:mi:ss'),
to_date('01/15/2015 23:59:00', 'mm/dd/yyyy hh24:mi:ss') from dual)
select to_char(report_time, 'mm/dd/yyyy hh24:mi:ss') report_time,
to_char(sales_time, 'mm/dd/yyyy hh24:mi:ss') sales_time,
round((report_time - sales_time) * 24, 6) diff_in_hours,
case when report_time < trunc(sales_time) + 2 then 'Y' else 'N' end decision
from sales
输出:
REPORT_TIME SALES_TIME DIFF_IN_HOURS DECISION
------------------- ------------------- ------------- --------
01/15/2015 11:59:00 01/15/2015 11:45:00 0,233333 Y
01/16/2015 23:59:00 01/15/2015 12:45:00 35,233333 Y
01/17/2015 00:00:01 01/15/2015 23:59:00 24,016944 N