0

我有以下查询:

    $result = query("SELECT IdUser, followingID FROM following WHERE IdUser = '%d' AND followingID = '%d'", $id, $followingID);

我想知道如果基于 0 和 1 计数的结果是 YES 或 NO,如果关系存在,我将如何返回?

4

1 回答 1

1

这是一种方法:

select (case when exists (SELECT IdUser, followingID
                          FROM following
                          WHERE IdUser = '%d' AND followingID = '%d'
                         )
             then 'YES' else 'NO'
         end) as YesOrNo
, $id, $followingID
于 2013-08-07T02:17:02.283 回答