码迷,mamicode.com
首页 > 其他好文 > 详细

开盘价,收盘价,最高价,最低价的再次分析

时间:2016-01-09 22:53:45      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

//最大值
select max(price) max,date from on_jiaoyi_into group by date
//最小值
select min(price) min,date from on_jiaoyi_into group by date
//开盘价
select a.price,a.date from 
(
select price,date from on_jiaoyi_into where sid=3
order by date,time 
) a group by date
//收盘价
select a.price,a.date from 
(
select price,date from on_jiaoyi_into where sid=3
order by date,time desc
) a group by date












select zdz.max,zxz.min,kpj.kpj,spj.spj from 

(/*最大值*/select max(price) max,date,id from on_jiaoyi_into group by date) zdz 

left join 

(/*最小值*/select min(price) min,date,id from on_jiaoyi_into group by date) zxz 

on zdz.id=zxz.id

left join

(/*开盘价*/select a.price kpj,a.date,a.id from (select price,date,id from on_jiaoyi_into where sid=3 order by date,time ) a group by date ) kpj

on zdz.id=kpj.id

left join

(/*收盘价*/select b.price spj,b.date,b.id from (select price,date,id from on_jiaoyi_into where sid=3 order by date,time desc) b group by date ) spj 

on zdz.id=spj.id

最后join出来的结果有一个字段是空值,最后想了想,因为他们的最大值、最小值、开盘价、收盘价有可能不是一个ID。。。。。

那么,只有把上面四条语句查询出来的结果用合并数组的方法才是正确的。。。

开盘价,收盘价,最高价,最低价的再次分析

标签:

原文地址:http://www.cnblogs.com/hellowzd/p/5117467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!