我在我的数据库中维护股票价格,这是我的数据库结构
CREATE TABLE `sector_wise` (
`symbol_name` varchar(50) DEFAULT NULL,
`sector_name` varchar(50) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
CREATE TABLE `historical_data` (
`symbol_name` varchar(70) DEFAULT NULL,
`current_day` date DEFAULT NULL,
`open_val` decimal(15,2) DEFAULT NULL,
`high_val` decimal(15,2) DEFAULT NULL,
`low_val` decimal(15,2) DEFAULT NULL,
`close_val` decimal(15,2) DEFAULT NULL,
`last_val` decimal(15,2) DEFAULT NULL,
`prevclose_val` decimal(15,2) DEFAULT NULL,
`volume` varchar(30) DEFAULT 'NA'
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
插入脚本:
Insert INTO sector_wise ('symbol_name','sector_name') VALUES ('VISESHINFO','Agriculture');
Insert INTO historical_data ('symbol_name','current_day','open_val','high_val','low_val','close_val','last_val','prevclose_val','volume') VALUES ('VISESHINFO','2016-05-03',0.05,0.10,0.05,0.05,0.05,0.10,45814.95);
这是我试过的查询
SELECT sw.symbol_name AS symbol_name,
hd.current_day AS curr_day,
hd.open_val AS open_value,
hd.high_val AS high_value,
hd.low_val AS low_val,
hd.close_val AS close_val,
hd.prevclose_val AS prevclose_val,
(close_val-prevclose_val)/close_val*100 AS per_change
FROM sector_wise sw,
historical_data hd
WHERE sw.symbol_name = hd.symbol_name
AND sw.sector_name = 'Agriculture'
AND hd.current_day =
(SELECT max(current_day)
FROM historical_data)
ORDER BY per_change;
执行上述查询后得到的结果实际上是错误的,百分比chnage应该是-50.00而不是-100.00
symbol_name curr_day open_value high_value low_value close_val prevclose_val percentage_change
VISESHINFO 2016-05-03 0.05 0.10 0.05 0.05 0.10 -100.000000
请您告诉我计算百分比变化的错误究竟在哪里
答案 0 :(得分:1)
(close_val-prevclose_val)/ close_val * 100将转换为以下内容:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
<base href="/" />
@Styles.Render("~/Content/css")
<link rel="stylesheet" type="text/css" href="~/Content/lib/theme.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="~/Content/lib/primeui-ng-all.min.css" />
<!-- 1. Load libraries -->
@*@Scripts.Render("~/startup");*@
<!-- IE required polyfills, in this exact order -->
<script src="~/Scripts/lib/breeze-client/breeze.min.js"></script>
<script src="~/Scripts/lib/es6-shim/es6-shim.min.js"></script>
<script src="~/Scripts/lib/systemjs/dist/system-polyfills.js"></script>
<script src="~/Scripts/lib/shims_for_IE.js"></script>
<script src="~/Scripts/lib/angular2/bundles/angular2-polyfills.js"></script>
<script src="~/Scripts/lib/systemjs/dist/system.src.js"></script>
<script src="~/Scripts/lib/primeui/primeui-ng-all.min.js"></script>
<script src="~/Scripts/lib/rxjs/bundles/Rx.js"></script>
<script src="~/Scripts/lib/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
defaultJSExtensions: true,
meta: {
'*.js': { scriptLoad: true } //this allows TS debugging in VS
},
packages: {
app: {
format: 'register',
defaultExtension: 'js'
},
},
map: {
'rxjs': 'scripts/lib/rxjs',
'angular2': 'scripts/lib/angular2',
'primeng': 'scripts/lib/primeng'
}
});
System.import('app/main')
.then(null, console.error.bind(console));
</script>
</head>
<body>
<div class="container body-content">
@RenderBody()
</div>
@RenderSection("scripts", required: false)
</body>
</html>
等于-100。你确定公式吗?如果是价格变化,那么不应该在公式中使用prevclose_val作为分母吗?
答案 1 :(得分:0)
我认为你只需要做(close_val / prev_close_val)* 100
答案 2 :(得分:0)
拥有: 收盘价= 0.05 Prev_close值= 0.10
Delta = 1-close_value/prev_close