sql题目 跪求解答解决办法
sql题目 跪求解答
article表
articleid title author
1 abc 张三
2 dfg 李四
3 jkl 王五
4 zxv 王五
version表
articleid version amendmentor amenddate
1 1 张三 2008-2-5
1 2 张三 2008-2-8
2 1 李四 2008-2-6
2 2 张三 2008-3-6
2 3 李四 2008-3-15
3 1 王五 2008-3-8
4 1 王五 2008-3-6
4 2 王五 2008-3-10
求取每篇文章(标题)最后更新的版本号和修订日期,并写出结果。
------解决方案--------------------
have a try
select a.title, b.version, b.amenddate
from article a,
(select max(version), articleid, amenddate from version
group by articleid, amenddate) b
where a.articleid = b.articleid
------解决方案--------------------
article表
articleid title author
1 abc 张三
2 dfg 李四
3 jkl 王五
4 zxv 王五
version表
articleid version amendmentor amenddate
1 1 张三 2008-2-5
1 2 张三 2008-2-8
2 1 李四 2008-2-6
2 2 张三 2008-3-6
2 3 李四 2008-3-15
3 1 王五 2008-3-8
4 1 王五 2008-3-6
4 2 王五 2008-3-10
求取每篇文章(标题)最后更新的版本号和修订日期,并写出结果。
------解决方案--------------------
have a try
select a.title, b.version, b.amenddate
from article a,
(select max(version), articleid, amenddate from version
group by articleid, amenddate) b
where a.articleid = b.articleid
------解决方案--------------------
- SQL code
select v.articleid ,a.title,v.amenddate from version v join (select articleid ,max(version) version from version group by articleid) t on (t.articleid = v.articleid and v.version = t.version) left join article a on (a.articleid = t.articleid);