0 0

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

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

 

id serialNo title status
10001 1 中国好声音 1
10001 2 中国好声音 1
10001 3 中国好声音 1
10002 1 天天向上 1
10002 2 天天向上 1
10002 3 天天向上 1
10003 1 非诚勿扰 1
10003 2

非常勿扰

1

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

 

id serialNo title status
10001 1 中国好声音 1
10002 1 天天向上 1
10003 1 非诚勿扰 1

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

2012年10月31日 10:36

7个答案 按时间排序 按投票排序

0 0

采纳的答案

加条件serialNo=1 不行吗?

2012年10月31日 10:43
0 0

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

2012年11月01日 17:09
0 0

方法一:开窗函数
方法二:用子查询(其中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

2012年10月31日 14:13
0 0

请使用开窗函数。

2012年10月31日 13:07
0 0

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

2012年10月31日 11:33
0 0

select * from TVShow group by id

2012年10月31日 11:12
0 0

select id,serialNo,distinct title, status from TVShow

2012年10月31日 11:11

相关推荐

Global site tag (gtag.js) - Google Analytics