Question

Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of...

Given the mySQL tables created below...


   Create a mySQL solution to return the itemIDs of items posted by user X, such that all the reviews are “Excellent” or “Good” for these items


CREATE TABLE Users (
   userId varchar (30) NOT NULL,
   pass varchar (30),
   fname varchar (50),
   lname varchar (50),
   email varchar (50),
   gender char(1),
   age integer,
   banned boolean,
   PRIMARY KEY (userId),
   UNIQUE(email))

CREATE TABLE FavSellers (
   userId varchar (30),
   sellerId varchar (30),
   PRIMARY KEY (userId, sellerId),
   FOREIGN KEY(userId) references Users,
   FOREIGN KEY(sellerId) references Users(userId))

CREATE TABLE Items (
   itemId integer,
   title varchar (50),
   desc varchar (255),
   posterId varchar (30),
   postTime DATETIME,
   price integer,
   PRIMARY KEY (itemId),
   FOREIGN KEY(posterId) references Users(userId))

CREATE TABLE ItemCategories (
   itemId integer,
   category varchar (50),
   PRIMARY KEY (itemId, category),
   FOREIGN KEY(itemId) references Items)

CREATE TABLE FavItems (
   itemId integer,
   userId varchar (30),
   PRIMARY KEY (itemId, userId),
   FOREIGN KEY(itemId) references Items,
   FOREIGN KEY(userId) references Users)

CREATE TABLE Reviews (
   reviewId integer,
   score varchar (50),
   remark varchar (255),
   submitTime Datetime,
   userId varchar (30) NOT NULL,
   itemId integer NOT NULL,
   PRIMARY KEY (reviewId),
   CHECK score IN ('Excellent, 'Good', ...),
   FOREIGN KEY (userId) references Users
   FOREIGN KEY (itemId) references Items)

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

Here I am providing the answer for the above question:

Query:

(SELECT itemID

FROM Reviews

WHERE score="Excelent" OR score="Good")

INTERSECT

(SELECT itemID

FROM Items , Users

WHERE userID=posterID AND fname="X");

Explanation:

First Query will return all itemids which are reviewed as "Excellent" ,"Good".

Second Query will return all items which are posted by user="X".

intersection of above two queries will return the all itemIDs which are posted by user"X" and reviewed as "Excellent" and "Good"

Hoping that the above answer will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
Given the mySQL tables created below...    Create a mySQL solution to return the itemIDs of...
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
  • Based on reference below. Write a relational algebra expression to return those users who have posted...

    Based on reference below. Write a relational algebra expression to return those users who have posted “excellent” reviews but never “poor” reviews. CREATE TABLE Users (             userId varchar (30) NOT NULL,             pass varchar (30),             fname varchar (50),             lname varchar (50),             email varchar (50),             gender char(1),             age integer,             banned boolean,             PRIMARY KEY (userId),             UNIQUE(email)) CREATE TABLE FavSellers (             userId varchar (30),             sellerId varchar (30),             PRIMARY KEY (userId, sellerId),...

  • CREATE TABLE Users (               userId varchar (30) NOT NULL,               pass varchar (30),     

    CREATE TABLE Users (               userId varchar (30) NOT NULL,               pass varchar (30),               fname varchar (50),               lname varchar (50),               email varchar (50),               gender char(1),               age integer,               banned boolean,               PRIMARY KEY (userId),               UNIQUE(email)) CREATE TABLE FavSellers (               userId varchar (30),               sellerId varchar (30),               PRIMARY KEY (userId, sellerId),               FOREIGN KEY(userId) references Users,               FOREIGN KEY(sellerId) references Users(userId)) CREATE TABLE Items (               itemId integer,               title varchar (50),              ...

  • 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));...

  • Define an SQL view JokesNum that gives the number of jokes each user posts on each...

    Define an SQL view JokesNum that gives the number of jokes each user posts on each day. 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));...

  • The following SQL DDL script creates a database for a social network application. create table userProfile(...

    The following SQL DDL script creates a database for a social network application. create table userProfile( id char(10) primary key, firstName varchar(20), lastName varchar(20), dob date, email varchar(30) ); create table foaf( userid char(10), friendID char(10), timeEstablished date, constraint pk primary key(userid, friendID), constraint fk1 foreign key(userid) references userProfile(id), constraint fk2 foreign key(friendID) references userProfile(id) ); create table activity( actID char(20) primary key, topic varchar(20), description varchar(100), location varchar(20), ActivityDate date, hostUser char(10), foreign key(hostUser) references userProfile(id) ); create table...

  • Use an INSERT INTO statement with a subquery containing a SQL string function to create user...

    Use an INSERT INTO statement with a subquery containing a SQL string function to create user names for the volunteers based on their legal names and insert them into the table. +----------------------+ | Tables_in_volunteers | +----------------------+ | address              | | email                | | funds                | | hours                | | person               | | phone                | | users                | +----------------------+ users legal names are in the address table user table is : CREATE TABLE USERS(volunteer_id INT NOT NULL, username VARCHAR(50), PRIMARY KEY...

  • I am trying to delete these tables from my data base and I keep getting: "mysql>...

    I am trying to delete these tables from my data base and I keep getting: "mysql> DROP TABLE Courses; ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails" I am using the command DROP TABLE Courses; Below is my sql file use sdev300; // Create a student table CREATE TABLE Students ( PSUsername varchar(30) primary key, FirstName varchar(30), LastName varchar(30), EMail varchar(60) ); CREATE TABLE Courses( CourseID int primary key, CourseDisc varchar(4), CourseNum varchar(4),...

  • Create a new database and execute the code below in SQL Server’s query window to create...

    Create a new database and execute the code below in SQL Server’s query window to create the database tables. CREATE TABLE PhysicianSpecialties (SpecialtyID integer, SpecialtyName varchar(50), CONSTRAINT PK_PhysicianSpecialties PRIMARY KEY (SpecialtyID)) go CREATE TABLE ZipCodes (ZipCode varchar(10), City varchar(50), State varchar(2), CONSTRAINT PK_ZipCodes PRIMARY KEY (ZipCode)) go CREATE TABLE PhysicianPractices (PracticeID integer, PracticeName varchar(50), Address_Line1 varchar(50), Address_Line2 varchar(50), ZipCode varchar(10), Phone varchar(14), Fax varchar(14), WebsiteURL varchar(50), CONSTRAINT PK_PhysicianPractices PRIMARY KEY (PracticeID), CONSTRAINT FK_PhysicianPractices_ZipCodes FOREIGN KEY (ZipCode) REFERENCES Zipcodes) go CREATE...

  • CREATE TABLE person ( pid INTEGER NOT NULL ,pname VARCHAR(30) NOT NULL ,PRIMARY KEY (pid) );...

    CREATE TABLE person ( pid INTEGER NOT NULL ,pname VARCHAR(30) NOT NULL ,PRIMARY KEY (pid) ); CREATE TABLE organization ( oid INTEGER NOT NULL ,oname VARCHAR(30) NOT NULL ,PRIMARY KEY (oid) ); CREATE TABLE venue ( vid INTEGER NOT NULL ,area CHAR(1) NOT NULL ,capacity INTEGER NOT NULL ,PRIMARY KEY (vid) ); CREATE TABLE calendar ( vid INTEGER NOT NULL ,date DATE NOT NULL ,price NUMERIC(6,2) NOT NULL ,PRIMARY KEY(vid,date) ,FOREIGN KEY(vid) REFERENCES venue(vid) ); CREATE TABLE event ( eid...

  • Using MySQL, you will create data base for given conditions and examine the mysqldump. •Create t...

    Using MySQL, you will create data base for given conditions and examine the mysqldump. •Create the table for the given data structure PASSENGERS: passengerid INTEGER, name VARCHAR(30), surname VARCHAR(30), email VARCHAR(50), address VARCHAR(100), city VARCHAR(30) FLT-SCHEDULE: fltno INTEGER, airlinename VARCHAR(50), dtime TIME, from-airportcode VARCHAR(5), atime TIME, to-airportcode VARCHAR(5), miles INTEGER, price INTEGER FLT-HISTORY: passengerid INTEGER, airlineid INTEGER, fltdate DATE AIRLINE: airlineid INTEGER, airlinename VARCHAR(50) -Conditions- For each passengers passengerid is neccessary (primary key). Name, surname, address information, city information, e-mail...

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