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),...

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

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

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

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

  • NEED HELP IN INSERT STATEMENTS FOR THE TABLES CAN YOU PLEASE ADD SOME INSERT STATEMENTS FOR...

    NEED HELP IN INSERT STATEMENTS FOR THE TABLES CAN YOU PLEASE ADD SOME INSERT STATEMENTS FOR A COMPANY SCHEMA SCRIPT. PLEASE ADN THANK YOU DROP TABLE dependent; DROP TABLE works_on; DROP TABLE project; DROP TABLE dept_locations; DROP TABLE department; DROP TABLE employee; CREATE TABLE employee ( fname varchar(15) not null, minit varchar(1), lname varchar(15) not null, ssn char(9), bdate date, address varchar(50), sex char, salary numeric(10,2), superssn char(9), dno numeric, primary key (ssn), foreign key (superssn) references employee(ssn) ); CREATE...

  • You have been given a univerity business plan that produced the following information: PERSON: lname, fname,...

    You have been given a univerity business plan that produced the following information: PERSON: lname, fname, rname, idnum, private, linkblue lname, fname, rname are variable length strings idnum is type INT and is a key attribute private is BOOLEAN linkblue is string of 8 characters CREATE TABLE PERSON (idnum INT NOT NULL PRIMARY KEY, lname varchar(40), fname varchar(40), rname varchar(40), private BOOLEAN, linkblue char(8) NOT NULL); ADVISOR: student, advisor student is a foreign key to PERSON.idnum advisor is a foreign...

  • Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names...

    Based on the CREATE TABLE statements, make an ER model of the database. Give suitable names to the relationships. (Remember cardinality and participation constraints.) The diagram must use either the notation used in the textbook (and the lectures) or the crow’s foot notation. To save you some time: There are a few tables that include the following address fields: Address, City, State, Country and PostalCode (and the same fields with the prefix Billing-). You are allowed to replace these attributes...

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