22,209
社区成员
发帖
与我相关
我的任务
分享
create table tmp (ID int, title Nvarchar(20), p2ID int, p2name Nvarchar(20))
GO
insert tmp(id,title,p2id,p2name) select 102 ,N'良安', 109 ,N'大礼堂'
union all select 102 ,N'良安', 110 ,N'良友厅'
union all select 102 ,N'良安', 111 ,N'良安厅'
union all select 72 ,N'君澜', 38 ,N'世贸厅'
union all select 72 ,N'君澜', 48 ,N'行政厅'
union all select 72 ,N'君澜', 49 ,N'总统厅'
union all select 92 ,N'威斯汀', 52 ,N'宝石厅'
union all select 92 ,N'威斯汀', 58 ,N'玛瑙厅'
union all select 94 ,N'开元', 93 ,N'天弘天'
GO
select top 3 *
from tmp a
where p2id=(select top 1 p2id from tmp where id=a.id order by newid())
order by newid()
GO
drop table tmp