
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显示
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)