我有此功能,我可以在其中计算db中的数据。
例如
Select column1, count(), column2
from table1
left join table 2 and so on
where --- some statement
and (table1.date - table2.date) <= 2
group by column1, column2
现在,我需要对要检查的每个数据在where子句中执行类似的操作,如果table2的状态为1,则where子句将为where status = 1,如果没有,则where where status = 2 >
这是因为我需要的是,如果table2中的状态为1,那就是我将在table2.date中使用的数据,否则,我将状态2的数据用作table2.date
答案 0 :(得分:1)
如果table2的状态为1,那么我的where子句将为where status = 1,但如果不是,则where status = 2
对我来说,这将转换为查询WHERE
子句中的以下条件:
(table2.status = 1 AND table1.status = 1) OR table1.status = 2
答案 1 :(得分:0)
假设NULL
列中没有status
值,则所需的逻辑是:
where (table2.status = 1 and table1.status = 1) or
(table2.status <> 1 and table1.status = 2)