select count(user_id) from users where user_id in (select user_friend_id from friend where user_id=241 and state=1) union select count(user_id) from users where user_id in (select user_id from friend where user_friend_id=241 and state=1)这个语句分别得到的是2和6,能不能把它合成一个句子得到的数是8?
from(
select count(user_id)a,0 as b from users where user_id in (select user_friend_id from friend where user_id=241 and state=1) union select 0,count(user_id) from users where user_id in (select user_id from friend where user_friend_id=241 and state=1))u
select count(*)
from users
where exists(select 1 from friend
where ((user_id=241 and users.user_id=friend.user_friend_id)
or (user_friend_id=241 and users.user_id=friend.user_id))
and state=1)
[/code]
你还可以把两个where条件用or并到一起,这样出来的就是8条