34,587
社区成员
发帖
与我相关
我的任务
分享
select distinct userID,b.xy as exYear
from userID,(select 2007 as xy union all select 2008 as xy union all select 2009 as xy) b
select userid,exYear
from tb
group by userid,exYear
order by userid,exYear
select * from (select 1 userid union all select 2) b ,
(select 2009 as exYear union all select 2008 union all select 2007) bb
userid exYear
1 2009
1 2008
1 2007
2 2009
2 2008
2 2007
(6 行受影响)
create table tb(userID int,exYear int)
insert into tb values(1 , 2007 )
insert into tb values(2 , 2007 )
insert into tb values(1 , 2008 )
go
select m.userid , n.exyear from
(select distinct userID from tb) m,
(select 2009 as exYear union all select 2008 union all select 2007) n
drop table tb
/*
userid exyear
----------- -----------
1 2009
1 2008
1 2007
2 2009
2 2008
2 2007
(所影响的行数为 6 行)
*/
ORDER BY userID, exYear DESC
select a.userid,b.exyear
from (select distinct userid from tb) a,
(select exyear=2007 union select 2008 union select 2009) b
select m.userid , n.exyear from
(select distinct userID from tb) m,
(select 2009 as exYear union all select 2008 union all 2007) n