sql - SQL 显示过去 30 天内和接下来 30 天内新开始的查询

在 Oracle OTBI 中创建报告以显示上个月或下个月内的任何新开始。

目前我有一个 SQL 查询,显示上个月内的新开始,但不确定如何制作它,以便它还包括下个月内开始的那些。

SELECT "Person Names"."Full Name" saw_0,
       "Worker"."Person Start Date" saw_1,
       "Worker"."Termination Date" saw_2,
       "Manager"."Business Unit" saw_3
  FROM "Workforce Management - Person Real Time"
 WHERE ("Manager"."Business Unit" = ' ')
   AND ("Worker"."Person Start Date" >= (TIMESTAMPADD(SQL_TSI_MONTH, -1, CURRENT_DATE)))

回答1

你可能想试试这个

SELECT    
"Person Names"."Full Name" saw_0,    
"Worker"."Person Start Date" saw_1,    
"Worker"."Termination Date" saw_2,    
"Manager"."Business Unit" saw_3    
FROM "Workforce Management - Person Real Time"    
where "Manager"."Business Unit" = ' '    
and "Worker"."Person Start Date" between sysdate -30 and sysdate +30

回答2

CREATE TABLE employees (employee_id, first_name, last_name, hire_date) AS
SELECT 1,  'Alice', 'Abbot', DATE '2022-04-03'  FROM DUAL UNION ALL
SELECT 2, 'Beryl', 'Baron',DATE '2022-05-01' FROM DUAL UNION ALL
SELECT 3, 'Carol', 'Chase',DATE '2022-05-18' FROM DUAL UNION ALL
SELECT 4, 'Debra', 'Doris', DATE '2022-05-28' FROM DUAL UNION ALL
SELECT 5, 'Emily', 'Evans',DATE '2022-06-30' FROM DUAL UNION ALL
SELECT 6, 'Fiona', 'Frank',DATE '2022-06-11' FROM DUAL UNION ALL
SELECT 7, 'Gemma', 'Grace', DATE '2022-06-30' FROM DUAL;

SELECT * FROM EMPLOYEES WHERE 
hire_date BETWEEN TRUNC(SYSDATE)-30
AND
TRUNC(SYSDATE)+ 30;


EMPLOYEE_ID    FIRST_NAME    LAST_NAME    HIRE_DATE
2    Beryl    Baron    01-MAY-22
3    Carol    Chase    18-MAY-22
4    Debra    Doris    28-MAY-22
6    Fiona    Frank    11-JUN-22

相似文章

javascript - 水平选中复选框时阻止 <select>

我在执行某个命令时遇到问题。单击复选框后,我希望它水平锁定字段。我需要代码来执行命令,单击“复选框”后它将阻止小时复选框。我已经尝试过If(),但它没有按应有的方式工作,将我锁定在所有领域,而不仅仅是...

python - Python - 在多行和多列中比较 values

我是Python的新手,我有一个如下所示的数据框(请参阅原始数据table)。最终目标是协调来自2个系统(sys1与sys2,在“源”列中标记)的记录(即id、rg、prd和数量)。我如何使用1个函数...

最新文章