求助再线等!!

davidjian 2003-08-30 01:35:14
(DB) There is a table called stockquotes, it has the following columns:
tradedate, symbol ,open, close, high, low.

Write a stored procedure that selects all the stocks(symbol) where a certain day's close is higher
than the previous trading day's (not necessarily the previous day because of holidy and weekend) high.
...全文
30 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
pengdali 2003-08-30
  • 打赏
  • 举报
回复
create proc getsymbol
@date datetime
as
begin
select * from stockquotes tem where datediff(day,tem.tradedate,@date)=0 and exists(select 1 from stockquotes where tradedate=(select max(tradedate) from stockquotes where datediff(day,tradedate,@date)>0) and symbol=tem.symbol and [close]<tem.[close])
end
go

---
declare @ datetime
set @=getdate()
exec getsymbol @
pengdali 2003-08-30
  • 打赏
  • 举报
回复
create proc getsymbol
@date datetime
as
begin
select * from stockquotes tem where datediff(day,tem.tradedate,@date)=0 and exists(select 1 from stockquotes where tradedate=(select max(tradedate) from stockquotes where datediff(day,tradedate,@date)>0) and symbol=tem.symbol and [close]<[tem.close])
end
go

---
declare @ datetime
set @=getdate()
exec getsymbol @
lionstar 2003-08-30
  • 打赏
  • 举报
回复
create proc usp_getsymbol
as
set nocount on
begin
select * from stockquotes a
inner join stockquotes b on a.symbol=b.symbol
where a.[close]>=b.[close]
and a.tradedate>b.tradedate
end
leimin 2003-08-30
  • 打赏
  • 举报
回复
/*There is a table called stockquotes, it has the following columns:
tradedate, symbol ,open, close, high, low.

Write a stored procedure that selects all the stocks(symbol) where a certain day's close is higher
than the previous trading day's (not necessarily the previous day because of holidy and weekend) high.
*/
create proc usp_getsymbol
as
set nocount on
begin
select * from stockquotes a
inner join stockquotes b on a.symbol=b.symbol
where b.[close]>=a.tradedate
end
txlicenhe 2003-08-30
  • 打赏
  • 举报
回复
1: you can use one statement to solve it, stored procedure is not necessary

Select * from stockquotes a where
(
select close from stockquotes where tradedate
= (select max(tradedate) from stockquotes where tradedate<a.tradedate)
) < close
zjcxc 元老 2003-08-30
  • 打赏
  • 举报
回复
up

e文水平不高.

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧