how do I subtract values from two select statements

Posted by fishhead on Stack Overflow See other posts from Stack Overflow or by fishhead
Published on 2010-04-09T21:48:02Z Indexed on 2010/04/09 21:53 UTC
Read the original article Hit count: 271

Filed under:

I would like to subtract one value from another value. The schema of the table is as follows:

   tag, datetime,value
   ------------
   tag1, 2010-1-1 10:10:00, 123
   tag2, 2010-2-2 10:12:00. 321

  select * from  

  ( (Select    Max(Value) as [Value1] from History WHERE Datetime ='2010-1-1 10:10'       and tagname ='tag1') as v1   -

  (  (Select    Max(Value) as [Value2] from History WHERE Datetime ='2010-1-1 10:12'      and Tagname ='tag2')  as v2))

obviously I am lost...how do I do this.

thanks

ms-sql

© Stack Overflow or respective owner

Related posts about sql-server