在where子句中使用“泪f”条件

在where子句中使用“泪f”条件,第1张

在where子句中使用“泪f”条件

select * from sampleTable
where
case when @taxtype = ‘P’ then
(taxtype = ‘P’ or (taxtype = ‘E’ and pre in (‘MER’,’SER’)))
Else
(taxtype = ‘E’ and pre not in (‘MER’,’SER’))
end


看起来这将与Postres一起使用

编辑:

留下我的原始答案是因为要点可行,但Postgres没有像其他RDBMS一样具有变量的概念,因此我将其重写

WITH myconstants as (SELECt 'P'::text as vtaxtype)select * from sampleTablewhere   case when (select vTaxType from myconstants) = 'P' then    (taxtype = 'P' or  (taxtype = 'E' and pre in ('MER','SER')))  Else    (taxtype = 'E' and pre not in ('MER','SER'))  end;

这是一个SQL Fiddle显示



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4907299.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存