0

I want to modify sql statement which is very simple like

SELECT id
FROM page
WHERE name = "Test"

Now I want to change it something like

SELECT id
FROM page
WHERE name = "Test"
AND if idLanguage != idlanguage then idParent = idpage

what will the better way to do this?

Thank you

4

3 回答 3

3
SELECT id
FROM page
WHERE name = "Test"
AND (idLanguage = idlanguage OR idParent = idpage)

更好,因为它是有效的 SQL 语法。

于 2012-12-13T10:25:49.733 回答
1

使用case语句怎么样?请试试:

SELECT id
FROM page
WHERE name = "Test" AND 
idParent = (CASE WHEN idLanguage <> idlanguage THEN idpage ELSE idParent END)
于 2012-12-13T10:28:42.873 回答
0

如果您真的想在数据库中设置 idParent 的值,那么您需要UPDATE在选择之前添加一条语句。

UPDATE page SET idParent = idpage
WHERE name = "Test"
    AND idLanguage != idlanguage;

SELECT id FROM page
WHERE name = "Test"
于 2012-12-13T10:28:22.633 回答