日期:2014-05-18 浏览次数:20473 次
select id from tb where Interest_Id=(select top 1 Interest_Id from tb where User_id=1) and User_id<>1
------解决方案--------------------
我插,被忽悠了
select id from tb where Interest_Id=(select top 1 Interest_Id from tb where [User_id]=1) and [User_id]<>1
------解决方案--------------------
又被忽悠了
select [User_id] from tb where Interest_Id=(select top 1 Interest_Id from tb where [User_id]=1) and [User_id]<>1
------解决方案--------------------
1 1
1 22 1
2 3
3 1
3 24 1
4 2
4 3
5 7
5 8
6 1
7 2
8 1
8 29 1
9 3
9 7
9 8
10 9
10 11
麻烦楼主把红色部分解释一下
------解决方案--------------------
create table abc ( userid int, Interestid int ); insert into abc values (1,1) insert into abc values (1,22) insert into abc values (2,3) insert into abc values (3,1) insert into abc values (3,24) insert into abc values (4,2) insert into abc values (4,3) insert into abc values (4,4) insert into abc values (4,5) insert into abc values (5,8) insert into abc values (6,1) insert into abc values (7,4) insert into abc values (8,1) insert into abc values (8,29) insert into abc values (9,11) select userid from abc where Interestid in (select count(Interestid)*10+userid+(select top 1 Interestid from abc) as row from abc group by userid)
------解决方案--------------------
/*
M
as
(
select distinct a.*,
case when a.zd1=b.zd1 then null else b.zd1 end as col1,
case when a.zd2=b.zd2 then null else b.zd2 end as col2,
case when a.zd1=b.zd1 and a.zd2=b.zd2 and a.zd3=b.zd3 then null else b.zd3 end as col3,
case when a.zd1=b.zd1 and a.zd2=b.zd2 and a.zd4=b.zd4 then null else b.zd4 end as col4
from T a inner join T b on a.zd1=b.zd1
)
select *from M
*/
select
case when px=1 then zd1 else null end as zd1,
case when px=1 then zd2 else null end as zd2,
case when a.zd3=zd3 then zd3 else null end as zd3,