求一比较函数 或者给个思路也可以 比如今天是周2到周5的任何一天,
周一的价格为 3200
周二的价格为 3300 (今天)的有一个价格差  就是3300-3200=100表示涨100周五的价格是 3400
如果今天是周一 价格为3350                   今天的价格涨跌就是3350-3400=-50 周六和周日不考虑。请问数据库可以自动实现吗并存储吗?

解决方案 »

  1.   

    select datepart(dw,日期字段) not in (1,7) 就可不考虑周六和周日的记录。
      

  2.   

    數據庫大概可以直接實現,舉個例子看看:
    declare @t table ([date] datetime,value int)
    insert into @t 
    select '2006-07-19',1000   /*上個星期3*/
    union
    select '2006-07-20',1500   /*上個星期4*/
    union
    select '2006-07-21',2500   /*上個星期5*/
    union
    select '2006-07-22',888    /*上個星期6*/
    union
    select '2006-07-23',8888   /*上個星期天*/
    union
    select '2006-07-24',2800   /*今天,星期1*/select [id]=identity(int,1,1),* ,tem=null into test from @t where datepart(dw,[date]) between 2 and 6select [date],value,tem=(select test.value-t.value from test t where t.[id]=test.[id]-1) from test where datediff(dd,[date],getdate())=0/*The result*/
    date                            value       tem         
    ------------------------------- ----------- ----------- 
    2006-07-24 00:00:00.000         2800        300
      

  3.   

    非常感谢 playwarcraft(三角褲叉叉的頂點) 
    有思路了。不过我还需要一些改动。 就此谢过