Question

stuck on creating view Use a SQL statement to create a view vIBM_MMM (year, month, IBM_price,...

stuck on creating view

Use a SQL statement to create a view vIBM_MMM (year, month, IBM_price,
MMM_price) that contains the year and month, average close prices of IBM and MMM for the
year/month. Your view should directly access the Historial_price table to have the latest data.

mysql> desc Historical_prices;

+-----------+-------------+------+-----+---------+----------------+

| Field | Type | Null | Key | Default | Extra |

+-----------+-------------+------+-----+---------+----------------+

| id | bigint(20) | NO | PRI | NULL | auto_increment |

| symbol | varchar(20) | YES | MUL | NULL | |

| date | date | YES | | NULL | |

| open | float | YES | | NULL | |

| high | float | YES | | NULL | |

| low | float | YES | | NULL | |

| close | float | YES | | NULL | |

| volumne | bigint(20) | YES | | NULL | |

| adj_close | float | YES | | NULL | |

+-----------+-------------+------+-----+---------+----------------+

9 rows in set (0.00 sec)

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

CREATE VIEW vIBM_MMM AS SELECT year(date) as year, month(date) as month, t1.IBM_Price, t2.MMM_price FROM Historical_prices hp, (SELECT avg(close) as IBM_Price FROM Historical_prices hp1 WHERE month(hp1.date) = month(hp.date) and year(hp1.date) = year(hp.date) and symbol = 'IBM') as t1, (SELECT avg(close) as MMM_Price FROM Historical_prices hp2 WHERE month(hp2.date) = month(hp.date) and year(hp2.date) = year(hp.date) and symbol = 'MMM');

Add a comment
Know the answer?
Add Answer to:
stuck on creating view Use a SQL statement to create a view vIBM_MMM (year, month, IBM_price,...
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
  • create a view vHW1_Q3 with columns (state, population, NumofZipcode) showing the total population and the number...

    create a view vHW1_Q3 with columns (state, population, NumofZipcode) showing the total population and the number of zip code (NumofZipcode) of each state and DC. The result should be sorted by the population size from high to low. The output should have 51 rows. using mysql Questions based on table Zipcode_info in datamining database. 50 US states and one DC means capital washington. these are fields in db +---------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default |...

  • Create a classrooms table with this definition (try using a multi-line SQL statement): +-----------+-----------------+------+-----+---------+----------------+ | Field...

    Create a classrooms table with this definition (try using a multi-line SQL statement): +-----------+-----------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-----------------+------+-----+---------+----------------+ | id | int(3) unsigned | NO | PRI | NULL | auto_increment | | room_num | int(4) unsigned | NO | UNI | NULL | | | course_id | int(3) unsigned | YES | MUL | NULL | | +-----------+-----------------+------+-----+---------+----------------+

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

  • 11. For each song in the songs table, update the value of artist_id to the id...

    11. For each song in the songs table, update the value of artist_id to the id of the corresponding artist in the artists table. 11.1. You must update all songs using only one UPDATE statement and a subquery. Hardcoded ids or names are not allowed in your query. 12. For each song in the songs table, update the value of genre_id to the id of the corresponding genre in the genres table. 12.1. You must update all songs using only...

  • Create SQL statements based on the given tables: Code to create the tables: CREATE DATABASE LAB...

    Create SQL statements based on the given tables: Code to create the tables: CREATE DATABASE LAB4DB; USE LAB4DB; CREATE TABLE CUSTOMER ( CUS_CODE int primary key, CUS_LNAME varchar(15), CUS_FNAME varchar(15), CUS_INITIAL varchar(1), CUS_AREACODE varchar(3), CUS_PHONE varchar(8), CUS_BALANCE float(8) ); INSERT INTO CUSTOMER VALUES('10010','Ramas','Alfred','A','615','844-2573','0'); INSERT INTO CUSTOMER VALUES('10011','Dunne','Leona','K','713','894-1238','0'); INSERT INTO CUSTOMER VALUES('10012','Smith','Kathy','W','615','894-2285','345.86'); INSERT INTO CUSTOMER VALUES('10013','Olowski','Paul','F','615','894-2180','536.75'); INSERT INTO CUSTOMER VALUES('10014','Orlando','Myron','','615','222-1672','0'); INSERT INTO CUSTOMER VALUES('10015','O''Brian','Amy','B','713','442-3381','0'); INSERT INTO CUSTOMER VALUES('10016','Brown','James','G','615','297-1228','221.19'); INSERT INTO CUSTOMER VALUES('10017','Williams','George','','615','290-2556','768.93'); INSERT INTO CUSTOMER VALUES('10018','Farriss','Anne','G','713','382-7185','216.55'); INSERT INTO CUSTOMER VALUES('10019','Smith','Olette','K','615','297-3809','0'); /*...

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