Sanet - ST B07CK3P1V2 PDF
Sanet - ST B07CK3P1V2 PDF
Sanet - ST B07CK3P1V2 PDF
TABLE DESIGN/STRUCTURE:
PRICE
Name Type
STOCK_ID INT(12) DATE_YYYYMMDD DATE
OPEN_PR FLOAT(24,2) HIGH FLOAT(24,2) LOW FLOAT(24,2)
CLOSE_PR FLOAT(24,2) VOLUME INT(12)
Nullable No
No
No
STOCK
Name Type
STOCK_ID INT(12) STOCK_NAME VARCHAR(10) REVENUE
DOUBLE(53,2) PRE_TAX_INCOME DOUBLE(53,2)
POST_TAX_INCOME DOUBLE(53,2)
Nullable No
No
TABLE DATA:
PRICE
STOCK_ID 1
1
2
2
3
3
STOCK
STOCK_ID 1
2
3
(
STOCK_ID INT(12) NOT NULL,
DATE_YYYYMMDD DATE NOT NULL,
OPEN FLOAT(24,2) NOT NULL,
HIGH FLOAT(24,2),
LOW FLOAT(24,2),
CLOSE FLOAT(24,2),
VOLUME INT(12)
);
The following table is being created so that it can be used to test alter table
and delete table statements
CREATE TABLE ALTERDROPTEST1
(
STOCK_ID INT(12) NOT NULL,DATE_YYYYMMDD DATE NOT
NULL,
OPEN FLOAT(24,2) NOT NULL,HIGH FLOAT(24,2),
LOW FLOAT(24,2),CLOSE FLOAT(24,2),VOLUME INT(12)
);
);
EXCHANGE
Name
EXCHANGE_ID
EXCHANGE_NAME SECTOR_NAME SECTOR_ID
Type
INT(12)
VARCHAR(10) VARCHAR(20) INT(12)
);
EQUITY
Name Type
STOCK_ID INT(12) EXCHANGE_ID INT(12) STOCK_NAME
VARCHAR(20) DATE_YYYYMMDD DATE
PRICE FLOAT(24,2)
Null able No
INSERT Statement:
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (1,’2013-06-
03’,’447.78’,’452.36’,’442.48’,’450.72’, 13239052);
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (1, ’2013-05-
31’,’452.5’,’457.1’,’449.5’,’449.74’, 13838340);
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (2, ’2013-06-
03’,’863.54’,’873.97’,’855.02’,’867.63’, 2473631);
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (2, ’2013-05-
31’,’868.12’,’877’,’867.52’,’871.22’, 2019407);
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (3, ’2013-06-
03’,’26.37’,’26.62’,’26.13’,’26.39’, 16445040);
INSERT INTO PRICE (STOCK_ID, DATE_YYYYMMDD, OPEN_PR,
HIGH, LOW, CLOSE_PR, VOLUME) VALUES (3, ’2013-05-
31’,’26.2’,’26.6’,’26.09’,’26.3’, 23906901);
COMMIT;
The following statements insert data into stock table (this is a shorter
statement as you can see):
EXCHANGE
EXCHANGE_ID EXCHANGE_NAME SECTOR_NAME
SECTOR_ID 1001 ICE Tech 1 1002 CME Commodities 2
SELECT statement:
Select * from price;
Select * from price order by date;--sorting by date
Select * from price order by volume; --sorting by volume
Select * from price where stock_id =1; --using ‘where’ clause to indicate
specifics.
Select * from stock where stock_name like ‘Google%’; --using ‘LIKE’ when you don’t know complete
name. Suffix. Select * from stock where stock_name like ‘% Inc’; --using ‘LIKE’ when you don’t know
sector_id=1;
Select * from equity where exchange_id =1001 and stock_name = ‘Google
Inc’;
UPDATE Statement:
The following statement updates the column ‘sector_name’ in table
‘exchange’ from ‘Commodities’ to ‘Manufacturing’
update Exchange set sector_name = ‘Manufacturing’ where exchange_id =
1002;
rollback; -- When you use ‘rollback’, the action of update statement is NOT
saved.
update Exchange set sector_name = ‘Manufacturing’ where exchange_id =
1002;
Commit; -- When you use ‘commit’, the action of update statement is saved.
DELETE Statement:
Delete from Exchange where exchange_id = 1002;
rollback; -- When you use ‘rollback’, the action of delete statement is NOT
saved. Delete from Exchange where exchange_id = 1002;
Commit; -- When you use ‘commit’, the action of delete statement is saved.
Run the following insert statement since we use this record in Joins
section. INSERT INTO EXCHANGE VALUES (1002,’CME’,
‘Commodities’, 2);
AGGREGATE FUNCTIONS:
Aggregate functions perform a calculation on a set of values and return a single value. Except for COUNT, aggregate functions ignore null values. Aggregate functions are frequently
used with the GROUP BY clause of the SELECT statement.
PRICE.STOCK_ID, PRICE.DATE_YYYYMMDD,
STOCK.STOCK_NAME,
PRICE.CLOSE_PR, PRICE.VOLUME, STOCK.REVENUE,
STOCK.POST_TAX_INCOME
FROM PRICE
INNER JOIN STOCK
ON PRICE.STOCK_ID = STOCK.STOCK_ID; --Enables you to choose
data from both tables that you want to see.
OUTER JOIN:
SELECT
A.STOCK_ID,A.DATE_YYYYMMDD,B.STOCK_ID,
B.DATE_YYYYMMDD,A.OPEN_PR,B.CLOSE_PR,
B.VOLUME
FROM PRICE A
INNER JOIN PRICE B
ON (A.STOCK_ID = B.STOCK_ID AND A.DATE_YYYYMMDD =
B.DATE_YYYYMMDD) WHERE A.OPEN_PR > B.CLOSE_PR;--A and
B are Aliases for the table stock
VIEW:
CREATE VIEW Statement:
CREATE VIEW STOCK_PRICE AS
SELECT PRICE.STOCK_ID, PRICE.DATE_YYYYMMDD,
STOCK.STOCK_NAME, PRICE.CLOSE_PR, PRICE.VOLUME
FROM PRICE
INNER JOIN STOCK
ON PRICE.STOCK_ID = STOCK.STOCK_ID;
RATE_TYPE
Name
RATE_TYPE_ID
RATE_TYPE_NAME TERM
Type
INT(12)
VARCHAR(30) VARCHAR(5)
Nullable No
Constraints PRIMARY KEY
RATE
Name
RATE_ID
RATE_TYPE_ID EXPIRY_DATE BID_RATE
ASK_RATE
MID_RATE
Type
INT(12)
INT(12)
DATE
FLOAT(24,4) FLOAT(24,4) FLOAT(24,4)
Nullable No
No
INSTRUMENT_TYPE Name
INSTRUMENT_TYPE_ID INSTRUMENT_TYPE
Type
INT(12)
VARCHAR(10) INT(12)
Type
INT(12)
Nullable No
Constraints PRIMARY KEY VARCHAR(25)
INSTRUMENT
Name
INSTRUMENT_ID
INSTRUMENT_TYPE_ID TENOR_ID
RATE_ID
INSTRUMENT_NAME STRIKE
Nullable No
Constraints PRIMARY KEY
Type
INT(12)
INT(12)
INT(12)
INT(12)
VARCHAR(50) INT(12)
Nullable No
No
RATE_TYPE
RATE_TYPE_ID RATE_TYPE_NAME TERM 11 LIBOR 1M 12
LIBOR 2M 13 LIBOR 3M 14 LIBOR 6M 15 LIBOR 9M
RATE
RATE_ID RATE_TYPE_ID EXPIRY_DATE 1 11 30-JUN-15 2 12 30-
JUN-16 3 13 30-JUN-17 4 14 30-JUN-18 5 15 30-JUN-19
BID_RATE ASK_RATE
0.024 0.04
0.028 0.04
0.031 0.04
0.033 0.04
.0352 0.04
MID_RATE
0.032
0.034
0.0355
0.0365
0.0376
TENOR
TENOR_ID TENOR_NAME TENOR_MONTHS 1 0M 0
2 3M 3
3 6M 6
4 9M 9
5 1Y 12
INSTRUMENT_TYPE
INSTRUMENT_TYPE_ID INSTRUMENT_TYPE 1
AMERICAN_CALL 2 AMERICAN_PUT 3 EUROPEAN_CALL 4
EUROPEAN_PUT 5 FORWARD
INSTRUMENT
INSTRUMENT_ID INSTRUMENT_TYPE_ID TENOR_ID RATE_ID
1 3 4 15 2 3 3 14 3 4 4 15 4 4 3 14 5 5 2 13
AAPL.100.EUROPEAN_PUT.9M 100
AAPL.150.EUROPEAN_PUT.6M 150
AAPL.200.FORWARD.3M 200