首页 新闻 会员 周边 捐助

请教一个SQL查询语句的写法

0
悬赏园豆:30 [已解决问题] 解决于 2009-04-17 22:12

Table Parent
Pid  Name
1    aa
2    bb
3    ddd
4    aaa

Table Child
Cid Pid Name
1   2   aa
2   1   bb
3   2   bb
4   3   cc
5   3   cd

Table Article
Aid Cid Context
1   3   asdfasdfasdf
2   2   asdfasdfasdfasf
3   3   asdfasdfasdfasdf
4   1   asdfasdfasdfasdf

想从每个Parent分类下相关的任意Child提取3条Article

问题补充: SQL2000的数据库
wuyou331的主页 wuyou331 | 初学一级 | 园豆:101
提问于:2009-04-07 22:42
< >
分享
最佳答案
0
WITH OrderedArticle AS
(
SELECT Pid, Aid, ROW_NUMBER() OVER (PARTITION BY Pid ORDER BY Aid) AS Num
FROM Parent
JOIN Child ON Parent.Pid = Child.Pid
JOIN Article ON Child.Cid = Article.Aid
)
SELECT *
FROM OrderedArticle
WHERE Num < 4
            
Azuresong | 老鸟四级 |园豆:3565 | 2009-04-08 00:48
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册