以下是表格结构,
create table WRITER (
id int primary key,
name varchar2(100)
)
create table TWEET(
id int primary key,
tweet varchar2(100),
createdDate TIMESTAMP,
writerid int foreign key references id of table WRITER
)
create table COMMENT (
id int primary key,
comment varchar2(1000),
createdDate TIMESTAMP,
tweetid int foreign key references id of table TWEET,
userid int foreign key references id of table USER
)
create table USER (
id int primary key,
name varchar2(100)
)
我尝试使用下面的查询,但它没有给出所需的输出。
SELECT id, tweetid, comment, createdDate
FROM COMMENT
WHERE tweetid in (SELECT id from TWEET WHERE writerid IN
(select id from WRITER WHERE name = 'Barack Obama'))
AND ROWNUM<11
GROUP BY id, tweetid, comment, createdDate
ORDER BY tweetid;
如何获得正确的输出?我需要最新的10条评论,每推特的'巴拉克奥巴马'
1条答案
按热度按时间kkbh8khc1#
你可以使用分析函数
ROW_NUMBER
具体如下:样本数据:
查询输出: