Question

QUESTION: (Answer in SQL) Write an SQL query to find all pairs of users (A,B) such...

QUESTION: (Answer in SQL) Write an SQL query to find all pairs of users (A,B) such that both A and B have blurted on a common topic but A is not following B. Your query should print the names of A and B in that order.

BACKGROUND INFO:

Users can post their thoughts in form of short messages that we call “blurts”. When signing up, users need to provide their email and a password of their choice. In addition, they need to enter some basic information – name, date of birth, address, email ID and hobbies. Once signed up, they can (besides blurting) “follow” other users. To “follow” a user means subscribing to his/her “blurts”. Users are categorized into “regular” users and “celebrities”. A celebrity has an associated website url and an attribute called “kind” indicating whether he is a politician, actor, singer, etc. Each
blurt by a user (regular or celebrity) is assigned an id.

Blurt ids are serial and unique to the “blurts” by a given user; the first blurt by a given user would have blurt id 1 and ids are incremented for each successive blurt by the user. Note that blurt ids are unique only to a user, so blurts by two different users may have the same blurt id.
Besides an id, each blurt also has its text, timestamp, and user location as additional attributes.

The system should have a pre-defined notion of “topics” that are simply subjects that people may blurt about. Examples of topics might include music, pollution, disease, disaster, sports, weather, etc. A topic has a unique id and description (the name of the topic).

Each blurt by a user is analyzed to associate with it zero or more topics. Related blurt-topic pairs are stored in blurt_analysis table. To account for the possible ambiguity arising from the choice of words or language used by a user, an association with a topic has a corresponding confidence level (an integer ranging from 1 – 10 indicating the strength of the association). For example consider the following blurt: “I absolutely hate the rainy weather, can’t go out, listening to the Beatles, just love them” is analyzed to be associated with two topics, weather and
music (Beatles).

For each topic, the associated sentiment is evaluated and quantified as an integral value ranging between -5 and 5, with higher values indicating a more positive sentiment. Considering the example blurt used above, the topic weather would have an associated sentiment of -5 (hate) while for music the corresponding value is 4 (love).

Note: You don’t need to implement the value constraint as
MySQL doesn’t support it.

A vendor has interest in one or more topics and is interested in tracking all users who are blurting about a topic of interest. A vendor may also have a celebrity as its brand ambassador. Vendors create advertisements that have an associated unique id and a textual content. These advertisements are stored in the system and are available to be shown to the regular set of users (that is, not to the celebrities, just to the other “regular” users). Careful matching is done based upon a historical analysis of all blurts by a user. Based upon the analysis, a user may be
shown zero or more advertisements.

SCHEMA:

user (email, password, name, date_of_birth, address, type)

celebrity (email, website, kind)

blurt (blurtid, email, text, location, time) foreign key(email) references user(email)

hobby (email, hobby) foreign key(email) references user(email))

follow (follower,followee) foreign key(follower) references user(email), foreign key(followee) references user(email))

vendor (id, name)

vendor_ambassador (vendorid, email) foreign key(email) references user(email), foreign key(vendorid) references vendor(id))

topic (id, description)

vendor_topics (vendorid,topicid) foreign key(vendorid) references vendor(id), foreign key(topicid) references topic(id))

blurt_analysis (email,blurtid,topicid,confidence,sentiment) foreign key(email,blurtid) references blurt(email,blurtid), foreign key(topicid) references topic(id)

advertisement (id, content, vendorid) foreign key(vendorid) references vendor(id))

user_ad (email,adid) foreign key(email) references user(email), foreign key(adid) references advertisement(id))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

SELECT U1.name, U2.name

FROM user U1, follow F, user U2, blurt_analysis B1, blurt_analysis B2

WHERE U1.email = F.follower AND F.followee <> U2.email AND U1.email = B1.email AND U2.email = B2.email AND B1.topicid = B2.topicid;

Add a comment
Know the answer?
Add Answer to:
QUESTION: (Answer in SQL) Write an SQL query to find all pairs of users (A,B) such...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write an SQL query to return the users who posted the most number of jokes on...

    Write an SQL query to return the users who posted the most number of jokes on 1/1/2019. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...

  • 4. Consider the following schema for an online streaming service, where users are allowed to play...

    4. Consider the following schema for an online streaming service, where users are allowed to play (stream) songs performed by different artists. Primary and foreign key constraints are also listed for the schema of each table. User (ID, Password, Name, Location) Primary key = ID Artist (ID, Name, Birthyear) Primary key = ID Song (ID, Title, Album, ArtistID) Primary key = ID Song(ArtistID) references Artist(ID) Play (ID, UserID, SongID, Timestamp) Primary key = ID Play(UserID) references User(ID) Play(SongID) references Song(ID)...

  • For each question, write a SQL query and save it as a "sql" file using a...

    For each question, write a SQL query and save it as a "sql" file using a different query 2, etc. Please execute these queries sequentially name, for example, query1.query product id (PK) category brand production_cost (Not Null) (FK) name (Not Null) Toothpaste Supermarket 1 Multivitami Supermarket 2 Shampoo acket T-shirt Supplements Supermarket Department4 Department5 Pharmacy Pharmacy 6 6 10 Query1. Update the Product table by adding another column as shown above ucts (name) with uery2. Retrieve all the uction cost...

  • What are your top 3 takaways from this article? It’s always tempting to see the present...

    What are your top 3 takaways from this article? It’s always tempting to see the present moment as the peak of chaos and disruption, whether we’re talking about politics or just how those teenagers behave today. The same is true in marketing, because in many ways that profession is always in a state of chaos and disruption. But I don’t think it’s hyperbole to apply “peak chaos and disruption” to social media marketing in the first quarter of 2018. Let’s...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT