3

我可以有这样的东西吗?

SELECT IF((SELECT COUNT(id) FROM table WHERE id = 1) = 0, 1, <nothing_to_happen>) AS Available

我的目标是选择这个:

+---------+
|Available|
+---------+
|1        |
+---------+

仅当没有从此查询中选择行时:

SELECT id FROM table WHERE id = 1

如果表中存在 id = 1 的行,我希望我的查询返回零行!那可能吗?

4

2 回答 2

5
SELECT  1
FROM    dual
WHERE   NOT EXISTS
        (
        SELECT  NULL
        FROM    mytable
        WHERE   id = 1
        )
于 2013-01-13T01:16:19.470 回答
0

询问:

SELECT CASE
           WHEN COUNT(id) = 0 THEN 1
           ELSE 0
       END AS Available
FROM `TABLE`
WHERE id = 1
于 2013-01-13T09:05:42.617 回答