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 '1980-1-1','hardcopy',8,1);
insert into Book values (6,'The Great Gatsby','Fitzgerald' ,date '1978-1-1', 'hardcopy',2,3);
insert into Book values (7,'This Side of Paradise','Fitzgerald' ,date '1973-1-1','hardcopy',1,1);
insert into Book values (8,'Tender is the Night','Fitzgerald' ,date '1979-1-1', 'hardcopy',6,18);
insert into Book values (9,'The Age of Innocence','Wharton' ,date '2012-1-1','hardcopy',3,5);
create table customer (
customer_id integer,
customer_name varchar(50),
primary key (customer_id));
insert into customer values (1,'John');
insert into customer values (2, 'Mary');
insert into customer values (3, 'Jake');
insert into customer values (4, 'Sam');
create table loan_event (
loan_id integer,
customer_id integer,
loan_date date,
payment number,
primary key (loan_id),
foreign key (customer_id) references customer(customer_id));
insert into loan_event values (1,1, date '2016-4-1', 0);
insert into loan_event values (2,1, date '2016-3-1', 3.5);
insert into loan_event values (3,1, date '2016-2-1', 0.5);
insert into loan_event values (4,2, date '2016-1-1', 0);
insert into loan_event values (5,3, date '2016-4-11', 0);
create table loan_detail (
loan_id integer,
book_id integer,
due_date date,
return_date date,
primary key(loan_id, book_id),
foreign key(loan_id) references loan_event(loan_id),
foreign key (book_id) references book(book_id));
insert into loan_detail values (1,1, date '2016-4-10', date '2016-4-5');
insert into loan_detail values (1,4, date '2016-4-10', date '2016-4-5');
insert into loan_detail values (1,5, date '2016-4-10', date '2016-4-10');
insert into loan_detail values (2,2, date '2016-3-10', date '2016-3-15');
insert into loan_detail values (3,3, date '2016-2-10', date '2016-3-15');
insert into loan_detail values (4,6, date '2016-1-10', date '2016-2-15');
insert into loan_detail values (4,7, date '2016-1-10', date '2016-2-15');
insert into loan_detail values (4,8, date '2016-1-10', date '2016-2-15');
insert into loan_detail values (5,9, date '2016-4-10', date '2016-4-15');
Give Sql Oracle statements for the following:
List the titles of books published after January 1, 1978 and contain the word ‘Sea’ in the title.
Update the Quantity of all books published before January 1, 1975 to 0.
Find out the average quantity of books published before January 1, 1980.
List the number of books published by each author. Please return the number of books and author name. (Here each edition of a book is considered one book)
List the names of authors who have published more than one book in the database. (Here each edition of a book is considered one book)
Return the IDs of the loans made by a customer named ‘John’.
Return the loan_date of the loans made by ‘John’.
Return the names of the customers and the IDs of their loans, including those who do not have loans.
List the titles of all the books borrowed by ‘John’.
List the names of the customers and their total payment. Hint: 1) Total payment of a member can be computed as the sum of the payments for all the loans made by that customer. 2) Use join and group by.
select * from book where Publish_date >'1978-1-1' and
Book_title LIKE '%Sea%';
UPDATE book SET Quantity= 0 WHERE Publish_date<'1975-1-1';
select AVG(Quantity) from book where
Publish_date<'1980-1-1';
select Quantity number,Autor from book;
select Author from book where COUNT(Quantity number)>1;
select loan_id from loan_event,customer where
customer.customer_id=loan_event.customer_id and
customer.customer_name='john';
select loan_date from loan_event,customer where
customer.customer_id=loan_event.customer_id and
customer.customer_name='john';
select loan_event.loan_id,customer.customer_id from
loan_event,customer where
customer.customer_id=loan_event.customer_id ;
select book.Book_title from book,customer,loan_detail where
customer.customer_id = loan_detail.customer_id and
loan_detail.book_id = book.Book_id;
SELECT customer.customer_name,
SUM(loan_event.paymentnumber)
FROM customer,loan_event
WHERE customer.customer_id=loan_event.customer_id
GROUP BY customer.customer_name,loan_event.paymentnumber;
Given: Create table Book ( Book_id integer, Book_title varchar(50), Author varchar(50), Publish_date date, Type varchar(30), Edition...
CREATE TABLE DEPT (
DEPTNO INTEGER NOT NULL,
DNAME VARCHAR(14),
LOC VARCHAR(13),
PRIMARY KEY (DEPTNO));
INSERT INTO DEPT VALUES (10,'SPORTS','NEW YORK');
INSERT INTO DEPT VALUES (20,'HOME','DALLAS');
INSERT INTO DEPT VALUES (30,'OUTDOOR','CHICAGO');
INSERT INTO DEPT VALUES (40,'CLOTHING','BOSTON');
CREATE TABLE EMP (
EMPNO INTEGER NOT NULL,
ENAME VARCHAR(10),
JOB VARCHAR(9),
MGR INTEGER,
SAL FLOAT,
COMM FLOAT,
DEPTNO INTEGER NOT NULL,
FOREIGN KEY (DEPTNO) REFERENCES DEPT (DEPTNO),
FOREIGN KEY (MGR) REFERENCES EMP(EMPNO),
PRIMARY KEY (EMPNO));
INSERT INTO EMP VALUES (7839,'KING','PRESIDENT',NULL,
5000,NULL,10);
INSERT INTO...
please answer 56789
CREATE TABLE ALLDRINKS( /* All legal drinks */
DRINK VARCHAR(30) NOT
NULL, /* Drink name */
CONSTRAINT DRINKNAME_PKEY PRIMARY KEY(DRINK) );
CREATE TABLE DRINKERS ( /* All drinkers */
DRINKER VARCHAR(30) NOT NULL,
CONSTRAINT DRINKERS_PKEY PRIMARY KEY (DRINKER));
CREATE TABLE LOCATED( /* Pubs have locations
*/
PUB
VARCHAR(30) NOT NULL, /* Pub
name */
STREET VARCHAR(30) NOT
NULL, /* Street name */
BLDG_NO DECIMAL(4) NOT
NULL, /* Building number */...
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...
Database Management
6. [5] Create the following table: CREATE TABLE customer ( cust_name VARCHAR(30) NOT NULL, address VARCHAR(60), UNIQUE (cust name, address)); A. Run the following inserts and explain why both work and how will you prevent it INSERT INTO customer VALUES ('Alex Doe', NULL); INSERT INTO customer VALUES ('Alex Doe', NULL); 7. [5] Modify the following table definition to ensure that all employees have a minimum wage of $10 CREATE TABLE employee ( empId INT PRIMARY KEY, empName VARCHAR(40)...
SQL
I have a database
CREATE TABLE vendor
( vid CHAR(2) NOT NULL,
vname VARCHAR(25) NOT NULL,
PRIMARY KEY (vid) );
CREATE TABLE category
( catid CHAR(2) NOT NULL,
catname VARCHAR(25) NOT NULL,
PRIMARY KEY (catid) );
CREATE TABLE product
( pid CHAR(3) NOT NULL,
pname VARCHAR(25) NOT NULL,
price NUMERIC (7,2) NOT NULL,
vid CHAR(2) NOT NULL,
categoryid CHAR(2) NOT NULL,
PRIMARY KEY (pid));
CREATE TABLE region
( rid CHAR NOT NULL,
rname VARCHAR(25) NOT NULL,
PRIMARY KEY (rid)...
CREATE TABLE Bill( bill_id char(15) PRIMARY KEY, bill_name VARCHAR(150) NOT NULL, dateOfVoteCommittee date, dateOfVote date, isPassed tinyint(1) CHECK (isPassed IN (0,1)), date_signed date, isVeto tinyint(1) CHECK (isVeto IN (0,1)), dateOfVote_override date, proposed_person_id INT, committee_id INT, foreign key(proposed_person_id) REFERENCES Congressman(person_id), foreign key(committee_id) REFERENCES Committee(committee_id) ); INSERT INTO Bill (bill_id, bill_name, dateOfVote, isPassed, date_signed, isVeto, dateOfVote_override, proposed_person_id, commitee_id) VALUES(1,'SB2 Florida Statutes',DATE'2019-03-27',1,DATE'2019-03-27',0,23,); *I am getting this error - mysql Mysql doesn't like the date entries in the insert statement. Schema above for reference.
MYSQL Questions: 1.For every author, display the number of books written by that author that is carried by Henry Books. Display the author number as ‘Author Number’, author name concatenated (first last) as ‘Author Name’, and the total number of books written by the author as ‘Number of Titles by Author’. List in descending order by author number. Limit the output to 10 rows. Insert your snip of the query and resultset together here. 2.Using a function, what are the...
1. Create the following tables and establish relationships. All fields are Varchar except parts price and date. Invoice Invoice_ID Customer_ID Part_Number Date Customer Customer_ID Customer_Name Customer_Address Customer_Telephone Parts Part_Number Part_Description Parts_Price Supplier_ID Supplier Supplier_ID Supplier_Name Supplier_Address Sales_Rep 10 points 2. Populate data (you make it up) use at least one insert into query for each table the rest you can enter in grid view. 10 points (queries) 3. Update one of the supplier’s address. 4. Add a field named supplier...
-- 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...
Given (Oracle) SQL Script " CREATE TABLE Members( MemberID NUMBER(4) NOT NULL PRIMARY KEY, MFirst VARCHAR(25) NOT NULL, MLast VARCHAR(25) NOT NULL, Street VARCHAR(64) NOT NULL, City VARCHAR(25) NOT NULL, State VARCHAR(2) NOT NULL, ZipCode NUMBER(5) NOT NULL, CreditLimit NUMBER(7,2) NOT NULL, Gender VARCHAR(1) NOT NULL CHECK (Gender IN('F','M')) ); CREATE TABLE Employees( EmployeeID NUMBER(3) NOT NULL PRIMARY KEY, EFirst VARCHAR(25) NOT NULL, ELast VARCHAR(25) NOT NULL, ...