表1: 列是A, 下边是表的查询数据  A
------
  19
  16
  14
  10请问我想取出第一列19 减去第二列16怎么写语句? 谢谢!

解决方案 »

  1.   

    --create test data
    create table A(id int)
    insert into A
    select  19
    union all
    select   16
    union all
    select   14
    union all
    select  10
    select identity(int,1,1) as ,id into #t from A
    select(select id from #t where =1)-(select id from #t where =3) as result
    --drop tables
    drop table A
    drop table #t
      

  2.   

    谢谢,我想用一个SELECT查出来呢?
      

  3.   

    create table t(A int)
    insert into t(A)
    select 19
    union all 
    select 16
    union all
    select 14
    union all
    select 10
     
     
    select identity(int,1,1) as id,A into #temp  from t 
     select t1.A-t2.A as A  from #temp t1
    left join  #temp  t2  on  t2.id=2
    where t1.id=1
      

  4.   

    create table A(A int)
    insert into A
    select  19
    union all
    select   16
    union all
    select   14
    union all
    select  10select distinct (select top 1 A from A)-
    (
    select top 1 A from A where A not in
    (
    select top 1 A from A
    )
    ) from Adrop table A
      

  5.   

    也可以这样:
    select 
    2*(select top 1 A from A)
    -(select sum(A) from (select top 2 A from A) t)楼上也可以去掉 distinctselect (select top 1 A from A)-
    (
    select top 1 A from A where A not in
    (
    select top 1 A from A
    )
    )