You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SQL技术需求:使用NOT IN子查询更新tblAbsence.Status字段

Update tblAbsence.Status Based on tblManning Required Threshold

Alright, let's tackle this update query for your leave approval logic. First, let's recap the tables and sample data we're working with to make sure we're on the same page:

Tables & Sample Data

tblAbsence

This table tracks leave requests with the following fields and sample entries:

NameStartEndStatus
John4/2/184/5/18Approved
Sue5/1/185/10/18Denied

tblManning

This table tracks staffing requirements per date:

DateRequired
4/1/183
4/2/184
4/3/182

Core Requirement

We need to update tblAbsence.Status to "Approved" for any leave request where all Required values in tblManning (for dates within the leave's start/end range) do not exceed our threshold (here, we're using 4 as the example threshold). Put another way: if there are no dates in the leave period where staffing requirements go over 4, the request gets approved.

Solution Query

Based on the logic you mentioned (updating records that aren't in the problematic subquery results), here's the SQL statement you need:

UPDATE tblAbsence
SET Status = 'Approved'
WHERE NOT EXISTS (
    -- Subquery checks if there's any date in the leave period with Required > threshold
    SELECT 1
    FROM tblManning
    WHERE tblManning.Date BETWEEN tblAbsence.Start AND tblAbsence.End
      AND tblManning.Required > 4 -- Replace with your actual threshold if needed
);

Breakdown of the Logic

  • The NOT EXISTS clause is key here: it looks for any date in the leave request's range where Required exceeds the threshold. If no such date exists, the subquery returns no rows, so NOT EXISTS evaluates to true, and we update the status to Approved.
  • This also handles leave periods that include dates not present in tblManning—since there's no Required value to exceed the threshold, those requests will also be marked as Approved. If you need to treat missing dates differently (e.g., only approve if all dates in the range exist in tblManning), we can adjust the query, but this matches the core requirement you described.

内容的提问来源于stack exchange,提问作者farmpapa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:31:28