方案一
只返回数字
SELECT DISTINCT IF(EXISTS(SELECT 1 FROM tb WHERE id=1), 1, 0) AS res FROM tb;
作为另一条sql赋值
SELECT
tb2.*,
IF(EXISTS(SELECT 1 FROM tb WHERE id=1), 1, 0) AS res
FROM tb2;
方案二
SELECT IF(COUNT(*), 1, 0) AS res FROM tb WHERE id = 1
--作为另一条sql赋值
SELECT
tb2.*,
(SELECT IF(COUNT(*), 1, 0) FROM tb WHERE id = 1) AS res
FROM
tb2;
OK.