gpt4 book ai didi

sql-server - Where 语句中的括号放置

转载 作者:行者123 更新时间:2023-12-02 12:45:44 24 4
gpt4 key购买 nike

我已阅读了一些资源并喜欢此网站上的帖子 Are brackets in the WHERE clause standard sql 。但是,我仍然无法让所有 where 过滤器正常工作。

运行以下代码时,我的结果仍然返回包含除我尝试过滤掉的值之外的值的记录。

我正在尝试返回具有 (1) 个 PT_ACUITY 等于 3 - 两个以上资源 且还具有 (2) 个 Track_Group 的所有值等于“ED 跟踪组”并且 (3) 其 CHECKIN_DATE_TIME 属于状态和结束日期变量,并且 (4) 也没有 REASON_FOR_VISIT包含任何通配符术语。

我希望返回的记录能够满足所有四个参数。谢谢!

use EMTCQIData

DECLARE @StartDate Date
DECLARE @EndDate Date

Set @StartDate = '01/01/2017'
Set @EndDate = '12/21/2018'

Select pt_fin, TRACKING_GROUP, PT_MRN, RESULT_DT_TM, NOTE_TYPE,
RESULT_TITLE_TEXT, AUTHOR, ACTION_PRSNL, Result

from ED_NOTES_MASTER

WHERE (TRACK_GROUP = 'ED Tracking Group')
AND (PT_ACUITY = '3 - Two+ Resources')
AND (CHECKIN_DATE_TIME > @StartDate and CHECKIN_DATE_TIME < @EndDate)
AND (REASON_FOR_VISIT Not Like '%asthma%')
Or (REASON_FOR_VISIT Not Like '%psych%')
Or (REASON_FOR_VISIT Not Like '%suicide%')
Or (REASON_FOR_VISIT Not Like '%suicidal%')
Or (REASON_FOR_VISIT Not Like '%homicide%')
Or (REASON_FOR_VISIT Not Like '%homicidal%')
Or (REASON_FOR_VISIT Not Like '%FD-12%')
Or (REASON_FOR_VISIT Not Like '%behavioral%')
OR (REASON_FOR_VISIT Not Like '%overdose%')
Or (REASON_FOR_VISIT Not Like '%aggression%')

最佳答案

首先,格式化您的查询将使其更具可读性,并且更容易可视化和剖析。

如果我理解你的问题。

WHERE  TRACK_GROUP = 'ED Tracking Group'
AND PT_ACUITY='3 - Two+ Resources'
AND CHECKIN_DATE_TIME > @StartDate
AND CHECKIN_DATE_TIME < @EndDate
AND ( REASON_FOR_VISIT Not Like '%asthma%'
AND REASON_FOR_VISIT Not Like '%psych%'
AND REASON_FOR_VISIT Not Like '%suicide%'
AND REASON_FOR_VISIT Not Like '%suicidal%'
AND REASON_FOR_VISIT Not Like '%homicide%'
AND REASON_FOR_VISIT Not Like '%homicidal%'
AND REASON_FOR_VISIT Not Like '%FD-12%'
AND REASON_FOR_VISIT Not Like '%behavioral%'
AND REASON_FOR_VISIT Not Like '%overdose%'
AND REASON_FOR_VISIT Not Like '%aggression%'
)

关于sql-server - Where 语句中的括号放置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54329234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com