select
a.*,
isnull(select count(*) from UserOnLine where RoomId=a.RoomId),0)
from
ChatRoom a
where
a.RoomType=1
a.*,
isnull(select count(*) from UserOnLine where RoomId=a.RoomId),0)
from
ChatRoom a
where
a.RoomType=1
a.RoomId,
a.RoomName,
isnull(count(b.UserId),0)
from
ChatRoom a
left join
UserOnLine b
on
a.RoomId=b.RoomId
group by
a.RoomId,a.RoomName
这是昨天有人帮我写的
今天我在上面加了一个条件:ChatRoom中的RoomType='1'
a.RoomNO,
a.RoomName,
isnull((select count(*) from UserOnLine where RoomId=a.RoomId),0)
from
ChatRoom a
where
a.RoomType=1
a.RoomId,
a.RoomName,
isnull(count(b.UserId),0)
from
ChatRoom a
left join
UserOnLine b
on
a.RoomId=b.RoomId
where
a.RoomType=1
group by
a.RoomId,a.RoomName
select a.RoomId,a.RoomName,count(distinct UserId) 在线人数 from ChatRoom a,UserOnLine b where b.RoomType=1 and a.RoomId=b.RoomId group by a.RoomId,a.RoomName
简直是我的偶像呀!~太谢谢了!~~~
select a.RoomId,a.RoomName,count(distinct UserId) 在线人数 from ChatRoom a,UserOnLine b where b.RoomType=1 and a.RoomId=b.RoomId group by a.RoomId,a.RoomName
这条要是UserOnLine中没数据的话,就没有结果了~~
(
select a.roomno,a.roomname,b.userid from chatroom a inner join useronline b on
a.roomno=b.room where a.roomtype=1
)
a
group by roomno,roomname
orderby roomno
(
select a.roomno,a.roomname,b.userid from chatroom a inner join useronline b on
a.roomno=b.room where a.roomtype=1
)
a
group by roomno,roomname
orderby roomno
这个的效率会不会很低哦?