【发布时间】:2018-07-14 20:28:07
【问题描述】:
SQL 查询
select
case
when t2.property = 'TEST_1' and
(t3.ltype like case when t3.lvalue=t1.DMetd and t3.ltype not in ('STATE','CITY') then t3.ltype end)
then t3.ltext
else null
end as myMethod
from
table1 t1
join
table2 t2 on t1.wid = t2.w_id
left join
tabl3 t3 on t3.lvalue = t2.mymethod
我的CASE声明:
(t3.ltype like case when t3.lvalue=t1.DMetd and t3.ltype not in ('STATE','CITY') then t3.ltype end
在我的查询中,我应该在 select 子句中,还是在 where 或 on 子句中写 case 语句?
样本数据:
在 table3 我有这样的列
ltext, lvalue, ltype, care, cr, method1, effective care, cr, newmethod,
urgent, UR, newmethod
我需要选择行
effective care, cr, newmethod
我需要忽略行
care, cr, method1
table2 我需要先检查
ON (t3.lvalue = t2.mymethod)
t2 的列 mymethod 具有 CR、AR、UR 等值
table1 - 列 Dmethd 的值类似于 CR、AR、UR
【问题讨论】:
-
您使用的是 Oracle 还是 SQL Server?不要为不使用的数据库添加标签。
标签: sql plsql sql-server-2012 case sql-server-2016