假设我有一个查询
create table friends (
userid int,
friend int,
status int
);
知道查询的哪一部分正在执行是否可行?
例如,下面的示例应该告诉1是否满足(userid=1 and friend=2)
或告诉2是否执行(friend=2 and userid=1 )
部分。
//wrong example
select status,@var
from friends
where @var:=(userid=1 and friend=2)
or @var:=(friend=2 and userid=1 );
答案 0 :(得分:3)
我想这就是你要找的东西:
SELECT status,
CASE
WHEN (userid=1 and friend=2) THEN 'opt1'
WHEN (friend=2 and userid=1) THEN 'opt2'
END AS 'var'
FROM friends
WHERE userid IN (1, 2)
OR friend IN (1, 2)