[英]Mysql how to write a query contains where followed by condition
I am writing one query, that needs to satisfy the following conditions.我正在编写一个查询,它需要满足以下条件。
select
field1, field2, field3
from
`tabFirstTable`as ft join
`tabSecondTable` as st
where
--Upto above its fine but how to turn below logic into query--
IF ft.approval_status in == 'Approved By Manager' and ft.status in ("Created", "Error")
and //some more conditions
ELSE ft.approval_status in == 'Approved By HOD' and ft.status in ("Initiated")
and //some more conditions
Because of the above issue currently writing two separate queries, which is not a good idea.由于上述问题,目前正在编写两个单独的查询,这不是一个好主意。 Please help.请帮忙。
Unless I am missing something or over simplifying除非我遗漏了什么或过度简化
WHERE
(ft.status IN ('Created', 'Error') AND
ft.approval_status = 'Approved By Manager' AND
//other stuff
)
OR
(ft.status = 'Initiated' AND
ft.approval_status = 'Approved By HOD' AND
//some more conditions
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.