SQL查询——现有如下需求,不知能否实现,恳求各位帮忙

假如,我现有如下表格TVShow:

 

idserialNotitlestatus
100011中国好声音1
100012中国好声音1
100013中国好声音1
100021天天向上1
100022天天向上1
100023天天向上1
100031非诚勿扰1
100032

非常勿扰

1

现在想用一条select语句实现如下的查询结果:

 

idserialNotitlestatus
100011中国好声音1
100021天天向上1
100031非诚勿扰1

也就是不让显示重复的id,但,其它字段必须都得显示出来。我试过用distinct,但还是没能达到我想要的这种效果~求解?谢谢了~

加条件serialNo=1 不行吗?

select id,serialNo,distinct title, status from TVShow

select * from TVShow group by id

SELECT id,SUM(serialNo) as serialNo,MIN(title) AS title,SUM(status) as status FROM TVShow GROUP BY id;呵呵 好好利用group by,distinct好像解决不了你的问题

请使用开窗函数。

方法一:开窗函数
方法二:用子查询(其中B.serialNo<A.serialNo 这个条件由自己的需要定)
select * from TVShow A

where not exists ( select 1 from TVShow B where B.id=A.id and B.serialNo<A.serialNo ) 2012-10-31 13:49

select t.* from TVShow t
where
t.serialNo in (select min(serialNo) from TVShow)
order by t.serialNo desc,t.id asc