Question

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 JokeTag(
jokeid integer,
tag varchar(50),
primary key(jokeid,tag),
foreign key(jokeid) references Jokes);

create table MyFavoriteJokes(
userid varchar(30),
jokeid integer,
primary key(userid, jokeid),
foreign key(userid) references User,
foreign key(jokeid) references Jokes);

create table Reviews(
reviewid integer,
score varchar(50),
remark varchar(255),
SUBMITtIME datetime,
userid varchar(30) not null,
jokeid integer not null,
primary key(reviewid),
foreign key (userid) references User,
foreign key (jokeid) references Jokes);

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

Create view JokesNum as Select userid, day(cast(posttime as date)) ,count(Jokeid) from Jokes inner join User on Jokes.authorid = User.userid group by userid, day(cast(posttime as date)) ;

Do ask if any doubt. Please upvote.

Add a comment
Know the answer?
Add Answer to:
Define an SQL view JokesNum that gives the number of jokes each user posts on each...
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));...

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

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

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

  • In this hands-on project, you will create an application that allows the user to connect to...

    In this hands-on project, you will create an application that allows the user to connect to a database and query the database. Write a Java query application that allows the user to connect to the books database and query the books database. Provide the following predefined queries: Select all authors from the Authors table Select a specific author and list all books for that author. Include each book’s title, year and ISBN. Display the appropriate data for each query. Given...

  • SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and...

    SQL Create a database called MyMusician Create three tables, one named “User”, one named “Song”, and one named “Playlist”. The “User” table should have a column for userID (integer, autoincrement, not null, primary key), username, and password. It should also have one column for a foreign key we will assign later called “playlistID” (integer). The “Playlist” table should have a “playlistID” (integer, autoincrement, not null, primary key), and a column for a foreign key we will assign later called “songID”...

  • 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 Command - Create a view called S LIST that lists the Cardholder Number, last name,...

    SQL Command - Create a view called S LIST that lists the Cardholder Number, last name, first name and due date for all cardholders who have not returned a book. Use the CREATE OR REPLACE VIEW AS ... command. TABLE CARD HOLDERS Cardholder Numberint NOT NULL CONSTRAINT CH PK PRIMARY KEY, First_Name varchar(10) NULL, LastName varchar(15) NULL, Address varchar(20) NULL, varchar(15) NULL, State char(2) NULL, Zip_Code char(5) NULL) City TABLE BOOKS CHECKED OUT Cardholder_Numberint NOT NULL, Book Numberint NOT NULL,...

  • /* I am executing following SQL statement for the below code but I am getting error....

    /* I am executing following SQL statement for the below code but I am getting error. Pls, upload screenshot after running it. SQL Statement: SELECT OfferNo, CourseNo FROM Offering WHERE OfferTerm = 'Sum' AND OfferYear = 2012 AND FacSSN IS NULL; */ CREATE TABLE STUDENT( StdSSN INT NOT NULL PRIMARY KEY, StdFName VARCHAR2(50), StdLName VARCHAR2(50), StdCity VARCHAR2(50), StdState VARCHAR2(2), StdZip VARCHAR2(10), StdMajor VARCHAR2(15), StdYear VARCHAR2(20) ); CREATE TABLE FACULTY( FacSSN INTEGER NOT NULL PRIMARY KEY, FacFName VARCHAR(50), FacLName VARCHAR(50), FacCity...

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

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