都在一个数据库里,用什么存储过程,用union all就可以了select * from rebounddata_all where date = @CurrentDate
union all
select * from rebounddata_all where date = dateadd(year, -1, @CurrentDate)
union all
select * from rebounddata_all where date = dateadd(month, -3, @CurrentDate)

解决方案 »

  1.   

    SELECT b.ticker,b.[date],a.[close],
    MIN(a1.[date]) AS [date(1y)],
    MIN(a1.[close]) AS [close(1y)],
    MIN(a2.[date]) AS [date(3m)],
    MIN(a2.[close]) AS [close(3m)]
    FROM rebounddata_all a 
    INNER JOIN briefingplatinum b 
    ON a.ticker=b.ticker 
    AND a.[date]=b.[date]
    INNER JOIN rebounddata_all a1 
    ON a.ticker=a1.ticker 
    AND Year(a.[date])-Year(a1.[date])=1 
    AND Month(a.[date])=Month(a1.[date]) 
    AND Day(a.[date])=Day(a1.[date])
    INNER JOIN rebounddata_all a2
    ON a.ticker=a2.ticker 
    AND Year(a.[date])=Year(a2.[date])
    AND Month(a.[date])-Month(a2.[date])=3
    AND Day(a.[date])=Day(a2.[date])
    GROUP BY b.ticker,b.[date],a.[close]
      

  2.   

    因为礼拜六和礼拜天是没有数据的,所以直接选对应的一年前或3个月前不一定有数据,碰到这种情况就要取礼拜五那天的数据所以用了top 1的方式,不知道还有没有其他方法