1

如果查询完成,我有这段代码显示“1”,当查询为空时如何显示“0”。

SELECT  1 as 'access' 
FROM  `mytable` 
WHERE  `name` = 'Prophet Muhammad' and id = 1;
4

2 回答 2

3

利用COUNT

SELECT  (COUNT(*) >= 1) as 'access' 
FROM    mytable
WHERE   name = 'Prophet Muhammad' and 
        id = 1;
于 2013-02-04T08:04:19.027 回答
1

您可以使用它,当查询返回至少一行时显示 1,否则显示 0:

SELECT EXISTS (SELECT Null
               FROM  `mytable` 
               WHERE  `name` = 'Prophet Muhammad' and id = 1) as Status
于 2013-02-04T08:12:09.807 回答