SQL 显示休假员工人数的查询
SQL Query to show number of employees on leave
我正在使用 Oracle APEX 20.1。在我的仪表板上,我想显示当前系统日期休假的员工人数。我有一个 leave_details table 和 emp_id 列,leave_start_date 列,leave_end_date 列,leave_status 列。我试过这个 SQL 查询:
select nvl(count(emp_id),0)
from leave_details
where to_char(leave_start_date,'dd-mon-rr') = to_char(sysdate,'dd-mon-rr')
and leave_status = 'Granted'
但它只会在 sysdate 与 leave_start_date 匹配时显示。我想在 leave_start_date 和 leave_end_date 之间的日子里在仪表板上显示它。我怎样才能做到这一点? This is what my dashboard looks like
据推测,日期存储为 dates 而不是字符串。所以就这样对待他们吧!
今天请假人数:
select count(*)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
leave_end_date >= trunc(sysdate) and
leave_status = 'Granted';
COUNT()
永远不会 returns 一个 NULL
值,因此不需要额外的逻辑来检查它。
请假结束是否计入请假期间不清楚。以上假设是。
注意:如果您有不确定的叶子,其中结束日期未知,那么您可以将其调整为:
select count(*)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
(leave_end_date >= trunc(sysdate) or leave_end_date is null) and
leave_status = 'Granted'
应该是
select count(1)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
leave_end_date >= trunc(sysdate) and
leave_status = 'Granted';
我正在使用 Oracle APEX 20.1。在我的仪表板上,我想显示当前系统日期休假的员工人数。我有一个 leave_details table 和 emp_id 列,leave_start_date 列,leave_end_date 列,leave_status 列。我试过这个 SQL 查询:
select nvl(count(emp_id),0)
from leave_details
where to_char(leave_start_date,'dd-mon-rr') = to_char(sysdate,'dd-mon-rr')
and leave_status = 'Granted'
但它只会在 sysdate 与 leave_start_date 匹配时显示。我想在 leave_start_date 和 leave_end_date 之间的日子里在仪表板上显示它。我怎样才能做到这一点? This is what my dashboard looks like
据推测,日期存储为 dates 而不是字符串。所以就这样对待他们吧!
今天请假人数:
select count(*)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
leave_end_date >= trunc(sysdate) and
leave_status = 'Granted';
COUNT()
永远不会 returns 一个 NULL
值,因此不需要额外的逻辑来检查它。
请假结束是否计入请假期间不清楚。以上假设是。
注意:如果您有不确定的叶子,其中结束日期未知,那么您可以将其调整为:
select count(*)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
(leave_end_date >= trunc(sysdate) or leave_end_date is null) and
leave_status = 'Granted'
应该是
select count(1)
from leave_details ld
where leave_start_date <= trunc(sysdate) and
leave_end_date >= trunc(sysdate) and
leave_status = 'Granted';