34,590
社区成员
发帖
与我相关
我的任务
分享
select convert(varchar(16),pushtime,120)时间,code as 代码,
(select top 1 price from tb b where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120) and not exists(select 1 from tb where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120) and pushtime<b.pushtime)) as 开盘价,
(select top 1 price from tb b where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120) and not exists(select 1 from tb where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120) and pushtime>b.pushtime)) as 收盘价,
(select max(price) from tb where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120)) as 最高价,
(select min(price) from tb where code=a.code and convert(varchar(16),pushtime,120)=convert(varchar(16),a.pushtime,120)) as 最低价
from tb a
--本人使用了求得的代码结果为:
/*
,最高价, 最低价, 开盘价, 收盘价, 代码, 市场
'2011-12-06 10:59',2322.958, 2322.519,2322.958,2322.602,'sh000001',73023080
'2011-12-06 11:00',2322.260, 2321.425,2322.045,2321.425,'sh000001',219297240
'2011-12-06 11:01',2321.979, 2321.613,2321.914,2321.819,'sh000001',109648620
*/
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),min(code),sum(market),max(pushtime)
from tb a group by convert(varchar(16),a.[date],120)
我解出来了,呵呵!