110,536
社区成员
发帖
与我相关
我的任务
分享
USE [test]
GO
/****** 对象: Table [dbo].[tb1] 脚本日期: 10/18/2010 17:28:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tb1](
[datetime] [datetime] NOT NULL,
[fcsthour] [int] NOT NULL,
[value] [int] NOT NULL
) ON [PRIMARY]
INSERT INTO [test].[dbo].[tb1]
([datetime]
,[fcsthour]
,[value])
VALUES
('2010-10-18 0:00:00'
,48
,40)
INSERT INTO [test].[dbo].[tb1]
([datetime]
,[fcsthour]
,[value])
VALUES
('2010-10-18 12:00:00'
,36
,30)
INSERT INTO [test].[dbo].[tb1]
([datetime]
,[fcsthour]
,[value])
VALUES
('2010-10-20 00:00:00'
,0
,0)
select t1.fcsthour as 时间,t1.[value] as 预测,t2.[value] as 实际,t1.[value]-t2.[value] as 误差
from tb1 as t1 left outer join tb1 as t2
on dateadd(hh,t1.fcsthour,t1.datetime)=t2.datetime
where t2.fcsthour=0
select t1.value,t2.value
from tb1 as t1 inner join tb1 as t2
on dateadd(hh,t1.fcsthour,t1.datetime)=t2.datetime
where t1.fcsthour=12 and t2.fcsthour=0