-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAll_Stocks_Moving_Average.sql
More file actions
85 lines (71 loc) · 3.52 KB
/
All_Stocks_Moving_Average.sql
File metadata and controls
85 lines (71 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
CREATE DEFINER=`root`@`localhost` PROCEDURE `All_Stocks_MovingAverage`()
BEGIN
/*Dropping the all stock Tables if already present*/
drop table IF EXISTS `assignment`.`BAJAJ1` ;
drop table IF EXISTS `assignment`.`eicher1` ;
drop table IF EXISTS `assignment`.`hero1` ;
drop table IF EXISTS `assignment`.`infosys1` ;
drop table IF EXISTS `assignment`.`tcs1` ;
drop table IF EXISTS `assignment`.`tvs1` ;
/*Cretaing the Table with 20days and 50 days Moving Average*/
/*BAJAJ1*/
CREATE TABLE `assignment`.`BAJAJ1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.bajaj b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
/*eicher1*/
CREATE TABLE `assignment`.`eicher1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.eicher b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
/*HERO1*/
CREATE TABLE `assignment`.`hero1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.hero b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
/*infosys*/
CREATE TABLE `assignment`.`infosys1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.infosys b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
/*tcs1*/
CREATE TABLE `assignment`.`tcs1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.tcs b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
/*TVS1*/
CREATE TABLE `assignment`.`tvs1` AS
(
select str_to_date(b.date, '%d-%M-%Y' ) AS DATE, b.`Close Price` AS `Close_Price`,
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 19 preceding), 2) as '20DayAverage',
round(avg(b.`Close Price`) over (order by str_to_date(b.date, '%d-%M-%Y' ) rows 49 preceding) , 2) as '50DayAverage'
FROM assignment.tvs b
where b.`Close Price` is not null
group by str_to_date(b.date, '%d-%M-%Y' )
order by str_to_date(b.date, '%d-%M-%Y' ) ) ;
END