+ -
当前位置:首页 → 问答吧 → 求sql语句。谢谢先

求sql语句。谢谢先

时间:2011-12-06

来源:互联网



如何找出将上述股票数据中每一分钟段中的,price字段中最高价,最低价,开盘价,收盘价。。

例如:2011-12-06 11:00分钟段,有12条数据,找出
最高价是2011-12-06 11:00:29的价格2322.26,
最低价是2011-12-06 11:00:59的价格2321.425
开盘价是2011-12-06 11:00:04的价格2322.045,
收盘价是2011-12-06 11:00:59的价格2321.425。

作者: qaqaqa   发布时间: 2011-12-06

表达形式:
每一分钟段中的,price字段中最高价一条sql语句
每一分钟段中的,price字段中最低价一条sql语句
每一分钟段中的,price字段中开盘价一条sql语句
每一分钟段中的,price字段中收盘价一条sql语句

作者: qaqaqa   发布时间: 2011-12-06

看不到图.
最高最低好弄,开盘收盘怎么判断?

作者: xuam   发布时间: 2011-12-06

补发图片

http://hi.csdn.net/attachment/201112/6/1396106_1323153449AJ2j.jpg

作者: qaqaqa   发布时间: 2011-12-06

作者: qaqaqa   发布时间: 2011-12-06

SQL code
select max(价格) 最高价,min(价格) 最低价,
       开盘价=(select top 1 价格 from tb 
where convert(varchar(16),[date],120)=convert(varchar(16),a.[date],120) order by [date]),
收盘价=(select top 1 价格 from tb 
where convert(varchar(16),[date],120)=convert(varchar(16),a.[date],120) order by [date] desc)
from tb a group by convert(varchar(16),a.[date],120)

作者: ssp2009   发布时间: 2011-12-06

做一个辅助列,表明某一个时间段内的交易顺序
然后计算即可

作者: Rock_Wu   发布时间: 2011-12-06

SQL code
select convert(varchar(10),dt,120)dt,max(price)最高价,min(price)最低价,
(select price from tb b where convert(varchar(10),dt,120)=convert(varchar(10),a.dt,120) and not exists(select 1 from where convert(varchar(10),dt,120)=convert(varchar(10),b.dt,120) and dt<a.dt)) as 开盘价,
(select price from tb b where convert(varchar(10),dt,120)=convert(varchar(10),a.dt,120) and not exists(select 1 from where convert(varchar(10),dt,120)=convert(varchar(10),b.dt,120) and dt>a.dt)) as 收盘价
from tb a

作者: qianjin036a   发布时间: 2011-12-06

一条语句还是多条语句?

作者: fredrickhu   发布时间: 2011-12-06

五楼七楼思路正确,楼主自己调一下应该可用可用

作者: wisters   发布时间: 2011-12-06