Question

please answer 56789

Tasks Download a file solution1.sql and insert into the file the implementations of the following queries as SELECT statement

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   */
   CONSTRAINT LOCATED_PKEY PRIMARY KEY(PUB) );

CREATE TABLE SERVES(   /* Pubs serve drinks */
PUB           VARCHAR(30)   NOT NULL,   /* Pub name   */
DRINK       VARCHAR(30)   NOT NULL,   /* Drink name   */
PRICE       DECIMAL(5,2)   NOT NULL,   /* Drink price   */
   CONSTRAINT SERVES_PKEY PRIMARY KEY(PUB, DRINK),
        CONSTRAINT SERVES_FKEY1 FOREIGN KEY(PUB)
       REFERENCES LOCATED(PUB),
   CONSTRAINT SERVES_FKEY2 FOREIGN KEY(DRINK)
       REFERENCES ALLDRINKS(DRINK) );

CREATE TABLE LIKES(   /* Drinkers like drinks   */
DRINKER       VARCHAR(30)   NOT NULL,   /* Drinker name   */
DRINK       VARCHAR(30)   NOT NULL,   /* Drink name   */
RATING       DECIMAL(1)   NOT NULL,   /* Rating of the drink   */
   CONSTRAINT LIKES_PKEY PRIMARY KEY(DRINKER, DRINK),
    CONSTRAINT LIKES_FKEY1 FOREIGN KEY(DRINK) REFERENCES ALLDRINKS(DRINK),
   CONSTRAINT LIKES_DKEY2 FOREIGN KEY(DRINKER) REFERENCES DRINKERS(DRINKER));

CREATE TABLE ORDERS(   /* Drinkers visit pubs and consumes drinks */
DRINKER       VARCHAR(30)   NOT NULL,   /* Drinker name   */
PUB           VARCHAR(30)   NOT NULL,   /* Pub name   */
ODATE       DATE       NOT NULL,   /* Order date   */
DRINK       VARCHAR(30)   NOT NULL,   /* Drink name   */
DRINK_NO   DECIMAL(2)   NOT NULL,    /* A sequence number of a drink */
   CONSTRAINT ORDERS_PKEY PRIMARY KEY(DRINKER, PUB, ODATE, DRINK, DRINK_NO),
   CONSTRAINT ORDERS_FKEY1 FOREIGN KEY(PUB, DRINK) REFERENCES SERVES(PUB, DRINK),
   CONSTRAINT ORDERS_FKEY2 FOREIGN KEY(DRINKER) REFERENCES DRINKERS(DRINKER)   );
COMMIT;
INSERT INTO LIKES VALUES('JOHN', 'RUM', 6);
INSERT INTO LIKES VALUES('JOHN', 'WHISKY', 1);
INSERT INTO LIKES VALUES('JOHN', 'BEER', 6);
INSERT INTO LIKES VALUES('JAMES', 'CHAMPAGNE', 6);
INSERT INTO LIKES VALUES('JAMES', 'COGNAC', 5);
INSERT INTO LIKES VALUES('JAMES', 'RUM', 4);
INSERT INTO LIKES VALUES('SERGIEY', 'VODKA', 6);
INSERT INTO LIKES VALUES('SERGIEY', 'RUM', 6);

NSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('8-JAN-2020', '%d-%M-%Y'), 'BEER', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('8-JAN-2020', '%d-%M-%Y'), 'BEER', 2);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('9-JAN-2020', '%d-%M-%Y'), 'RED WINE', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('10-JAN-2020', '%d-%M-%Y'), 'BEER', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('10-JAN-2020', '%d-%M-%Y'), 'BEER', 2);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('10-JAN-2020', '%d-%M-%Y'), 'BEER', 3);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('11-JAN-2020', '%d-%M-%Y'), 'WHITE WINE', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('12-JAN-2020', '%d-%M-%Y'), 'BEER', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('13-JAN-2020', '%d-%M-%Y'), 'BEER', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('14-JAN-2020', '%d-%M-%Y'), 'RED WINE', 1);
INSERT INTO ORDERS VALUES('JANUSZ', 'LONG JOHN', STR_TO_DATE('14-JAN-2020', '%d-%M-%Y'), 'RED WINE', 2);
INSERT INTO LIKES VALUES('SERGIEY', 'CHAMPAGNE', 3);
INSERT INTO LIKES VALUES('CLAUDE', 'CHAMPAGNE', 6);
INSERT INTO LIKES VALUES('CLAUDE', 'WHITE WINE', 5);
INSERT INTO LIKES VALUES('CLAUDE', 'COGNAC', 4);
INSERT INTO LIKES VALUES('CLAUDE', 'WHISKY', 3);
INSERT INTO LIKES VALUES('CLAUDE', 'RED WINE', 6);

INSERT INTO SERVES VALUES('LAZY LOBSTER', 'BEER', 5.00);
INSERT INTO SERVES VALUES('LAZY LOBSTER', 'RED WINE', 7.00);
INSERT INTO SERVES VALUES('LAZY LOBSTER', 'PORT', 8.00);
INSERT INTO SERVES VALUES('LAZY LOBSTER', 'COGNAC', 10.20);
INSERT INTO SERVES VALUES('LAZY LOBSTER', 'WHISKY', 6.90);
INSERT INTO SERVES VALUES('GREASY FORK', 'BEER', 5.20);
INSERT INTO SERVES VALUES('GREASY FORK', 'RED WINE', 7.40);
INSERT INTO SERVES VALUES('LONG JOHN', 'BEER', 5.90);
INSERT INTO SERVES VALUES('LONG JOHN', 'RED WINE', 8.00);
INSERT INTO SERVES VALUES('LONG JOHN', 'WHITE WINE', 9.00);
INSERT INTO SERVES VALUES('LONG JOHN', 'VODKA', 6.00);
INSERT INTO SERVES VALUES('LONG JOHN', 'PORT', 9.35);
INSERT INTO SERVES VALUES('LONG JOHN', 'COGNAC', 12.90);

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

(5) SELECT statement with ORDER BY ... DESC to order rating in descending order.
SELECT DRINK, RATING
FROM LIKES
ORDER BY RATING DESC;

(6) SELECT statement with GROUP BY clause to min function to find minimum price of drink.
SELECT DRINK, MIN(PRICE)
FROM SERVES
GROUP BY DRINK;

(7) SELECT statement with WHERE clause for condition and GROUP BY to count total drink of drinker.
SELECT DRINKER, COUNT(DRINK) AS TOTALDRINK
FROM ORDERS
WHERE ODATE > "1-JAN-2020"
AND ODATE < "31-MAR-2020"
GROUP BY DRINKER;

(8) SELECT statement with GROUP BY clause for using sum function for rating.
SELECT DRINK, SUM(RATING) AS TOTALRATING
FROM LIKES
GROUP BY DRINK;

(9) Subquery display pub with total drinks, and main query display the same but with the condition of total drinks more than 3.
SELECT t1.PUB, t1.TOTALDRINKS FROM
(SELECT PUB, COUNT(DRINK) AS TOTALDRINKS FROM SERVES
GROUP BY PUB) t1
WHERE t1.TOTALDRINKS > 3;

Add a comment
Know the answer?
Add Answer to:
please answer 56789 CREATE TABLE ALLDRINKS(   /* All legal drinks */ DRINK       VARCHAR(30)   NOT NULL,  ...
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
  • Consider a database with the following schema. LIKES(drinker,beer); /* key: all columns */ FREQUENTS(drinker,pub); /* key:...

    Consider a database with the following schema. LIKES(drinker,beer); /* key: all columns */ FREQUENTS(drinker,pub); /* key: all columns */ SERVES(pub,beer,cost); /* key: (pub,beer) */ Write the following queries in relational algebra. You can use the math notation (greek letters sigma, pi, etc.) or the ASCii "linear" notation I used in class. In order to make things more clear, please use intermediate results defined with the assignment notation in the algebra: R(a,b) := <rel-alg expression>. Try to give meaningful names for...

  • Database Management 6. [5] Create the following table: CREATE TABLE customer ( cust_name VARCHAR(30) NOT NULL,...

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

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

  • Relation Students has schema: CREATE TABLE Students (     BannerID CHAR(9),     stuName VARCHAR(40) NOT NULL,...

    Relation Students has schema: CREATE TABLE Students (     BannerID CHAR(9),     stuName VARCHAR(40) NOT NULL,     scholarship INT,     PRIMARY KEY(BannerID)); The relation Students is currently empty. Develop a test that determines whether an insertion into Students is currently legal. Then apply your test to determine which of the following INSERT statements is allowable.             a. INSERT INTO Students VALUES(950111333, ’John Smith’, 1000); b. INSERT INTO Students (BannerID, stuName) VALUES(‘950111333’, ’John Smith’); c. INSERT INTO Students VALUES(‘950111222’, NOT NULL,...

  • CREATE TABLE DEPT ( DEPTNO INTEGER NOT NULL, DNAME VARCHAR(14), LOC VARCHAR(13), PRIMARY KEY (DEPTNO)); INSERT...

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

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

  • Query 1: Retrieve names of all the projects as well as First and Last name of...

    Query 1: Retrieve names of all the projects as well as First and Last name of managers if they are working on any of these projects. Database: //STEP #1: 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 decimal(10,2), Super_ssn char(9), dno char(4), primary key (ssn)); CREATE TABLE department ( dname varchar(25) not null, dnumber char(4), Mgr_ssn char(9) not null, Mgr_start_date date, primary key (dnumber)); CREATE...

  • Help please ASSIGNEMENT 1: Create table NATION along with following data: 40create table nation 41 (natcode char(3) not null 42 natname varchar (20) 43 exchrate decimal(9,5) 44 constraint pk natio...

    Help please ASSIGNEMENT 1: Create table NATION along with following data: 40create table nation 41 (natcode char(3) not null 42 natname varchar (20) 43 exchrate decimal(9,5) 44 constraint pk nation primary key (natcode))s 45 Add data into the table nation 46insert into nation values ('UK', 'United Kingdom',1) 47insert into nation values USA, 'United States',0.67) 48insert into nation values ('AUS,'Australia',0.46) 49insert into nation values (' IND,India',0.8228) DELIVERABLE 1: Screen shot evidence of the above table and data in MySQL workbench ASSIGNEMENT...

  • drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not...

    drop table department cascade constraints; create table department ( Dname   varchar2(15)   not null, Dnumber int   not null, Mgr_ssn   char(9)   not null, mgr_start_date   Date, primary key (Dnumber), Unique    (Dname)); insert into DEPARTMENT values ('Research', '5', '333445555', '22-May-1988'); insert into DEPARTMENT values ('Administration', '4', '987654321', '01-Jan-1995'); insert into DEPARTMENT values ('Headquarters', '1', '888665555', '19-Jun-1981'); drop table employee cascade constraints; create table employee ( Fname   varchar2(15) not null, Minit   char(1), Lname   varchar2(15) not null, Ssn   char(9), Bdate   date, Address   varchar2(30), Sex   char(1),...

  • Create a procedure to update the sales history table following the requirements below. A table creation...

    Create a procedure to update the sales history table following the requirements below. A table creation script is provided below. a) Call the procedure: UPDATE_SALES_HISTORY (The procedure name is important for our scripts to test and grade your code; please do not rename it (otherwise our scripts will not run and your score will be 0). b) The procedure takes 2 parameters: (4-digit-year, 2-digit-month). Both parameters will be numeric, e.g., (2019, 11) will denote 2019 (year) and November (month). The...

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