-
Given the below table Content,
-
find number of comments for each originating post on '2015-09-07'.An originating post is the first post when person posts to her newsfeed.
-
find the distribution for the number of comments on an originating post on '2015-09-07'. Basically--the number of posts on '2015-09-07' that recieved 0 comments, 1 comment, 2 comments, .... max comments.
-
find the distribution for number of comments on an originating post on '2015-09-07' for each type.
Column Type Example ContentID INT 1 UserID INT 2 Date Date '2015-09-15' Type VARCHAR(50) One of ['like', 'url', 'comment', 'photo', 'share', etc] ReferenceID INT The ContentID for the original post; NULL if this is an original post -
-
Open postgres on the work stations by opening finder and typing "postgres"
-
Open PostgresSQL:
psql -
In your terminal, create your database:
CREATE DATABASE socialnetwork; -
quit SQL:
\q -
create content table using given sql commands or the following command if you cloned this repo:
psql socialnetwork < create_content_table.sql
-
Now hopefully you have content table
psql socialnetwork
contentid | userid | date | type | referenceid ----------+--------+------------+---------+------------- 1 | 1 | 2015-09-07 | url | 2 | 1 | 2015-09-07 | url | 3 | 2 | 2015-09-07 | comment | 2 4 | 3 | 2015-09-07 | comment | 2 5 | 3 | 2015-09-07 | comment | 2 6 | 4 | 2015-09-07 | share | 7 | 4 | 2015-09-07 | comment | 6 10 | 7 | 2015-09-07 | photo | 8 | 5 | 2015-09-08 | photo | 9 | 5 | 2015-09-08 | comment | 8 11 | 4 | 2015-09-07 | comment | 6 12 | 4 | 2015-09-07 | share | 13 | 4 | 2015-09-07 | comment | 12
Answers are in the sql_solution.sql file.