Question

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

              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)

Based on the information given , write a SQL solution to each of the following problem:

a). Return the item IDs of those items that are posted by users who are banned now.

b). Return the item IDs of those items that contain a comment that is given by a user who

is banned now.

c). Return the item IDs of those items, each comment of which is given by a user who is

banned now.

d). Return the item IDs of all the items that have no categories.

e). Return the item IDs of the items that have both categories of “electronics” and

“iphone”.

f). Return the user IDs of those female users who never posted any items but gave some

comments to some items.

g). Return the user IDs of those male users who only posted items but never gave any

comments.

h). Write an UPDATE statement to ban the users who neither posted any items nor gave

any comments.

i). Write a DELETE statement to delete all the users who posted at least 10 empty items

– those items that have no description.

j). Return the user IDs of the users who have posted items as well as some comments to

some items.

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

Database Create

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(userId),FOREIGN KEY(sellerId) references Users(userId));


CREATE TABLE Items (itemId integer,title varchar (50),descibe 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(itemId));
CREATE TABLE FavItems (itemId integer,userId varchar (30),PRIMARY KEY (itemId, userId),FOREIGN KEY(itemId) references Items(itemId),FOREIGN KEY(userId) references Users(userId));


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

a)

select itemId from Items where posterId in(Select userId from Users where banned ='FALSE');

b)

Select itemId from Reviews where userId in (Select userId from Users where banned ='FALSE');
c)
Select distinct itemId from Reviews where userId in (Select userId from Users where banned ='FALSE');
d)

Select itemId from Items where itemId not in(Select distinct itemId from ItemCategories)

e)
Select itemId from ItemCategories where category='electronics'and itemId in(Select itemId from ItemCategories where category='iphone');

f)
Select userId from users where gender='female' and userId not in (Select posterId from Items) and userId in(Select userId from Reviews);

g)

Select userId from users where gender='male' and userId in (Select posterId from Items) and userId not in(Select userId from Reviews);

h)
update users set banned='False' where userId not in(Select userId from Reviews);

i)

Delete from Users where userId in(Select posterId from items where descibe=''group by posterId having count(*)>10);

j)

Select posterId "UserID" from items where posterId in(Select distinct userId from Reviews)

if you still have any Problem regarding this question please comment and if you like my code please appreciate me by thumbs up thank you.........

Add a comment
Know the answer?
Add Answer to:
CREATE TABLE Users (               userId varchar (30) NOT NULL,               pass varchar (30),     
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),...

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

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

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

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

  • CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People (...

    CREATE TABLE Gender ( gender CHAR(1), description VARCHAR(10), PRIMARY KEY (gender) ); CREATE TABLE People ( ID INT, name VARCHAR(50), gender CHAR(1), height FLOAT, PRIMARY KEY (ID), FOREIGN KEY (gender) REFERENCES Gender (gender) ); CREATE TABLE Sports ( ID INT, name VARCHAR(50), record FLOAT, PRIMARY KEY (ID), UNIQUE (name) ); CREATE TABLE Competitions ( ID INT, place VARCHAR(50), held DATE, PRIMARY KEY (ID) ); CREATE TABLE Results ( peopleID INT NOT NULL, competitionID INT NOT NULL, sportID INT NOT NULL,...

  • -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),    ...

    -- Schema definition create table Customer (     cid   smallint not null,     name varchar(20),     city varchar(15),     constraint customer_pk         primary key (cid) ); create table Club (     club varchar(15) not null,     desc varchar(50),     constraint club_pk         primary key (club) ); create table Member (     club varchar(15) not null,     cid   smallint     not null,     constraint member_pk         primary key (club, cid),     constraint mem_fk_club         foreign key (club) references Club,     constraint mem_fk_cust...

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

  • Given: Create table Book ( Book_id integer, Book_title varchar(50), Author varchar(50), Publish_date date, Type varchar(30), Edition...

    Given: Create table Book ( Book_id integer, Book_title varchar(50), Author varchar(50), Publish_date date, Type varchar(30), Edition number, Quantity number, Primary key (Book_id) ); insert into Book values (1,'The Old Man and the Sea','Hemingway' ,date '1978-1-1','hardcopy',3,2); insert into Book values (2,'The Old Man and the Sea','Hemingway' ,date '1979-1-1','hardcopy',4,1); insert into Book values (3,'The Old Man and the Sea','Hemingway' ,date '1980-1-1', 'hardcopy',5,10); insert into Book values (4,'A Farewell to Arms','Hemingway' ,date '1986-1-1','hardcopy',2,18); insert into Book values (5,'For Whom the Bell Tolls','Hemingway' ,date...

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