如果查询完成,我的代码显示“1”,查询为空时如何显示“0”。
SELECT 1 as 'access'
FROM `mytable`
WHERE `name` = 'Prophet Muhammad' and id = 1;
答案 0 :(得分:3)
使用COUNT
SELECT (COUNT(*) >= 1) as 'access'
FROM mytable
WHERE name = 'Prophet Muhammad' and
id = 1;
答案 1 :(得分:1)
你可以使用它,当查询返回至少一行时显示1,否则显示0:
SELECT EXISTS (SELECT Null
FROM `mytable`
WHERE `name` = 'Prophet Muhammad' and id = 1) as Status