如何在sql语句的where子句中设置任何标志?

如何在sql语句的where子句中设置任何标志?,sql,oracle,Sql,Oracle,为了使用以下条件检索值,我编写了以下SQL查询。现在,如果我想在任何比较的末尾设置一个标志,我该怎么做 select x.transaction_id from nsbt_atm_trx_log_13763 x inner join nsbt_host_trx_log_13763 y on x.transaction_id = y.transaction_id where to_char(x.transaction_date) &l

为了使用以下条件检索值,我编写了以下SQL查询。现在,如果我想在任何比较的末尾设置一个标志,我该怎么做

 select 
     x.transaction_id 
 from 
     nsbt_atm_trx_log_13763 x 
 inner join  
     nsbt_host_trx_log_13763 y on x.transaction_id = y.transaction_id
 where  
     to_char(x.transaction_date) <> to_char(y.transaction_date) 
     or to_char(x.business_date) <> to_char(y.business_date) 
     or to_char(x.transaction_value_date) <> to_char(y.transaction_value_date) 
     or x.transaction_type<> y.transaction_type 
     or x.account_number <> y.account_number 
     or x.customer_id <> y.customer_id 
     or x.transaction_amount <> y.transaction_amount;
选择
x、 事务处理id
从…起
nsbt_atm_trx_日志_13763 x
内连接
nsbt_主机_trx_日志_13763 y在x.transaction_id=y.transaction_id上
哪里
to_char(x.交易日)to_char(y.交易日)
或to_char(x.业务日期)to_char(y.业务日期)
或to_char(x.交易_值_日期)to_char(y.交易_值_日期)
或x.交易类型y.交易类型
或x.账号y.账号
或x.客户识别码y.客户识别码
或x.交易金额y.交易金额;
现在,在每个“或”条件结束时,我需要设置一个标志。比如,如果第一个条件为真,那么我想将flag设置为1,对于第二个条件,我想将其设置为2。等等。

您可以在输出中使用“case-when”条件,如下所示

select x.transaction_id 
case when to_char(x.transaction_date)<>to_char(y.transaction_date) then 1 else
case when to_char(x.business_date)<>to_char(y.business_date) then 2 else
case when to_char(x.transaction_value_date) <> to_char(y.transaction_value_date) then 3 else
case when  x.transaction_type<> y.transaction_type then 4 else
case when  x.customer_id <> y.customer_id then 5 else 6 end end end end end
as columnname
from nsbt_atm_trx_log_13763 x inner join  nsbt_host_trx_log_13763 y on x.transaction_id = y.transaction_id
 where  to_char(x.transaction_date)<>to_char(y.transaction_date) or
 to_char(x.business_date)<>to_char(y.business_date) or
 to_char(x.transaction_value_date) <> to_char(y.transaction_value_date) or
 x.transaction_type<> y.transaction_type or
 x.account_number <> y.account_number or
 x.customer_id <> y.customer_id or
 x.transaction_amount <> y.transaction_amount;
选择x.transaction\u id
在将字符(x.transaction\u date)转换为字符(y.transaction\u date)的情况下,选择1个其他
案例:何时将字符(x.business\u date)转换为字符(y.business\u date),然后是其他2个
案例:何时将字符(x.交易\值\日期)转换为字符(y.交易\值\日期),然后是其他3个
如果x.transaction\u类型为y.transaction\u类型,则为4 else
当x.customer\u id y.customer\u id然后5其他6结束时的情况
列名
从nsbt_atm_trx_log_13763 x内部加入nsbt_主机_trx_log_13763 y on x.transaction_id=y.transaction_id
从何处到字符(x.交易日期)到字符(y.交易日期)或
至字符(x.业务日期)至字符(y.业务日期)或
至字符(x.交易\值\日期)至字符(y.交易\值\日期)或
x、 交易类型y。交易类型或
x、 账户号码y。账户号码或
x、 客户id y.客户id或
x、 交易金额y.交易金额;

您不能像您所说的那样嵌入
标志集
,但我尝试使用case和if语句,但无法实现。请仅使用适当的rdbms标记问题。这个sql在mysql和sql server中能正常工作吗?很抱歉错误的标记
到\u char(x.transaction\u date)到\u char(y.transaction\u date)
首先,为什么要比较字符串而不是日期?其次,为什么您依赖于特定于语言环境的NLS设置?必须始终明确指定格式模型。你应该保持日期不变,以便比较。