在我的查询中,我想检查具有指定权限的用户是否存在。目前我正在使用以下查询。它将检索具有指定条件的授权用户行。
select a.ixUserAuthorization from tblechecklistuserroleassignmentxref r
inner join tblechecklistuserrole u on u.ixUserRole=r.ixUserRole and u.sname='Initiator'
inner join tblechecklistuserauthorization a on a.ixUserAuthorization=r.ixUserAuthorization
and a.ixcustomer='1'and a.ixprogram='1'and a.ixworkpackage='1'and a.ixactivity='1' and a.ixUser='626e28e8-e67a-4d11-8d2c-129d0ab79e96';
如果返回任何行,我想将结果显示为true,如果上述查询没有返回任何行,我想将结果显示为false。
如何修改以获得真或假的结果。
答案 0 :(得分:1)
SELECT CASE
WHEN Count(*) >= 1 THEN 'true'
ELSE 'false'
END AS Answer
FROM (SELECT a.ixUserAuthorization
FROM tblechecklistuserroleassignmentxref r
INNER JOIN tblechecklistuserrole u
ON u.ixUserRole = r.ixUserRole
AND u.sname = 'Initiator'
INNER JOIN tblechecklistuserauthorization a
ON a.ixUserAuthorization = r.ixUserAuthorization
AND a.ixcustomer = '1'
AND a.ixprogram = '1'
AND a.ixworkpackage = '1'
AND a.ixactivity = '1'
AND a.ixUser = '626e28e8-e67a-4d11-8d2c-129d0ab79e96') a
答案 1 :(得分:1)
使用函数mysql_num_rows
例如:
if(mysql_num_rows($result))
echo "true";
else
echo "false";
其中$ result是您的查询结果