mysql-replace-into-with-if语句

nfg76nw0  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(355)

我有一个名为“支持的\u语言”的表,如下所示:

-----------------------------------------------------------
language_ref   |   language _name   |   language_active   |
-----------------------------------------------------------
en             |    English         |        Y            |
-----------------------------------------------------------
es             |    Espanol         |        Y            |
-----------------------------------------------------------
fr             |    Francias        |        Y            |
-----------------------------------------------------------
he             |    hebrew          |       NULL          |
-----------------------------------------------------------

我想创建一个查询,只有当3种语言-en、es、fr是活动的(y)和“he”语言为空时(与提供的表相同),才会将英语语言设置为活动的。只有在这种情况下-改变一切在“语言\活跃”下,保持英语是唯一活跃的语言。
有什么帮助吗?
谢谢!

nlejzf6q

nlejzf6q1#

你会想把这样的东西放到一个更新触发器中。

if exists (select * from supported_languages where language_ref = 'en' and language_active = 'Y')
    and exists (select * from supported_languages where language_ref = 'es' and language_active = 'Y')
    and exists (select * from supported_languages where language_ref = 'fr' and language_active = 'Y')
    and exists (select * from supported_languages where language_ref = 'he' and language_active = 'N')
    update supported_languages set language_active = 'N' 
where language_ref = 'es' or language_ref = 'fr'

相关问题