我們正在使用SQL創建一個類似twitter的數據庫。我在創建存儲過程時遇到問題:SQL - 允許用戶使用
允許用戶在他/她的推文中檢索最常用的哈希標籤。
UPDATE:這是我的存儲過程
create or replace
procedure TOP_2_FREQUENT_HASHTAGS is
first_hashtag varchar2(255);
second_hashtag varchar2(255);
begin
with TopTwoHashtags
AS (
SELECT
t.userID,
th.HASHTAGID,
ROW_NUMBER() OVER (ORDER BY COUNT(th.TWEETID) DESC) r
FROM
Tweet_Hashtag th
INNER JOIN Tweets t
ON th.TWEETID = t.TWEETID
WHERE
userID = t.userid
GROUP BY
t.userID,
th.HASHTAGID
)
SELECT
ht.TOPIC
into first_hashtag
FROM
Hashtag ht
INNER JOIN TopTwoHashtags tt
ON ht.HASHTAGID = tt.HASHTAGID
WHERE
r < 3;
dbms_output.put_line('Top 2 most frequent hashtags: '|| first_hashtag);
exception
when no_data_found then
dbms_output.put_line('This user does not exist');
return;
end;
我們有如下表:
- 聯繫
- 按照
#標籤
- HASHTAGID
- TOPIC
Tweet_Hashtag
- TWEETHASHID
- TWEETID
- HASHTAGID
- 鳴叫
- TWEETID
- USERID
- TWEETDATE
- TWEETTIME
- TWEETTEXT
- TwitUser
這是我們存儲用於搜索鳴叫的過程:
create or replace
procedure search_tweets(ttwitext in tweets.tweettext%type, tuserID in tweets.userid%type)
is
twit_user tweets.userid%type;
twit_id tweets.tweetid%type;
twit_text tweets.tweettext%type;
begin
select tweettext into twit_text from tweets where userid = tuserid and tweettext like '%' ||ttwitext || '%';
if twit_text is not null then
dbms_output.put_line(twit_text);
end if;
exception
when no_data_found then
dbms_output.put_line('kersplat');
return;
end;
似乎並沒有在這裏不被任何明顯的邏輯通過頻率排名#標籤。你有什麼嘗試? – woemler 2013-04-24 16:48:01
我希望有人指出我開始這個正確的方向。以上代碼僅搜索推文。 – MySalsa 2013-04-24 19:42:15