BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / database / #2582同步于 2008/10/19
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Database机器人发帖

[求助]大唐微电子一道数据库题

wuzw091
2008/10/19镜像同步15 回复
题目如下: 表名:testshow ID 名称 种类ID 显示次数 ID fname sortID showtimes 1 A 1 200 2 B 1 340 3 C 2 1000 4 D 1 130 5 E 3 360 6 F 2 400 要求:根据种类ID(sorid)查询出2个显示次数(showtimes)最高的所有信息。 万分感谢!
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
edis机器人#1 · 2008/10/19
大唐微电子还出数据库的题?!
wuzw091机器人#2 · 2008/10/19
恩,智能卡题,出了两个大题
xjy110207机器人#3 · 2008/10/19
select top 2 * from (select * from table order by showtimes) sqlserver 下应该可以
wuzw091机器人#4 · 2008/10/19
先谢谢楼上。不过貌似答案和要求不合,要求应该是求出每个分类的前两项。
kdsyan机器人#5 · 2008/10/19
select * from ( select row_number() over (partiton by sortID order by showtimes desc) rank, sortID,showtimes from testshow ) where rank in (1,2)
everdie机器人#6 · 2008/10/19
select * from (select * from table ordered by showtimes DES limited 2) ?
xt9876机器人#7 · 2008/10/20
我只想到了一种 showtimes 不重复时的方法(至少每个sortID内)。 select sortID,max(showtimes) as s from testshow group by sortID union select sortID,max(showtimes) as s from (select * from testshow where (sortID ,showtimes) not in (select sortID,max(showtimes) as s from testshow group by sortID)) 这样就联出了一个每种的前两个最大次数的表 然后在原表中继续找 对应信息就够了。 。。 select * from testshow where (sortID,showtimes) in ( select sortID,s from (select sortID,max(showtimes) as s from testshow group by sortID union select sortID,max(showtimes) as s from (select * from testshow where (sortID,showtimes) not in (select sortID,ma x(showtimes) as s from testshow group by sortID) ) ) ) order by sortID,showtimes; 【 在 wuzw091 (随风而飘) 的大作中提到: 】 : 题目如下: : 表名:testshow : ID 名称 种类ID 显示次数 : ...................
wuzw091机器人#8 · 2008/10/20
太强悍了。 【 在 kdsyan 的大作中提到: 】 : select * from ( : select row_number() over (partiton by sortID order by showtimes desc) rank, : sortID,showtimes : ...................
flyfrog机器人#9 · 2008/10/21
想了很久搞不定,学习 ~