-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.sql
38 lines (32 loc) · 967 Bytes
/
tweet.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
CREATE TABLE tweet
(
tweetId VARCHAR(20) NOT NULL,
userId VARCHAR(15) NOT NULL,
userName VARCHAR(150) NOT NULL,
PRIMARY KEY(tweetId)
);
PARTITION TABLE tweet ON COLUMN tweetId;
CREATE TABLE hashtag
(
tweetId VARCHAR(20) NOT NULL,
hashtag VARCHAR(150) NOT NULL,
);
PARTITION TABLE hashtag ON COLUMN tweetId;
CREATE PROCEDURE tweetinsert PARTITION ON TABLE tweet COLUMN tweetId
AS UPSERT INTO tweet (tweetId, userId, userName) VALUES (?, ?, ?);
CREATE PROCEDURE hashtaginsert PARTITION ON TABLE hashtag COLUMN tweetId
AS INSERT INTO hashtag (tweetId, hashtag) VALUES (?, ?);
CREATE PROCEDURE hashtagcount AS
SELECT distinct hashtag, count(hashtag) as Number
FROM hashtag
GROUP BY hashtag
ORDER BY Number DESC
LIMIT 10;
CREATE PROCEDURE mosttweetuser AS
SELECT DISTINCT userName, count(userName) as Number
FROM tweet
GROUP BY userName
ORDER BY Number DESC
LIMIT 3;
CREATE PROCEDURE tweetcount AS
SELECT count(*) FROM tweet;