本人有一个表(table1)字段及内容如下:
a1    a2    a3   a4
1    200   100  NULL
2    400   200  200
3    500   null 300本人想得出一个数据集,要求a2>a4,即可。
我是这样写的:select * from table1 where a2>a4;
执行不行。

解决方案 »

  1.   

    select * from table1 where a2>isnull(a4,0)
      

  2.   

    select * from table1 where a2>a4 and a2 <> null and a4 <> null;
      

  3.   

    可以,但是要考虑a4还有null值呢!!
      

  4.   

    select * from table1 where isnull(a2,0)>isnull(a4,0);
      

  5.   

    maerfeng(maerfeng) ( ) 信誉:100  2007-08-13 10:47:39  得分: 0  
     
     
       可以,但是要考虑a4还有null值呢!!
      
    ------------
    select * from table1 where IsNull(a2, 0) > IsNull(a4, 0)
      

  6.   

    上面写得都不对,对于a4,NULL的值,可否作为0来参与运算。
      

  7.   

    ntcxh(cai) ( ) 信誉:98  2007-08-13 10:50:12  得分: 0  
     
     
       上面写得都不对,对于a4,NULL的值,可否作为0来参与运算。
      
     
    -----
    是啊
      

  8.   

    難道是a4不為空的就拿來比較
    select * from table1 where a2>a4 and a4 <>null
      

  9.   

    上面我写错了,应该是写得都基本上对。
    我的要求是不管a4是否为空值,如果为空值作为0,与a2进行比较,a2一定不为空。
      

  10.   

    目前我用的是access数据库,有关系吗?
      

  11.   

    出错信息如下:[Microsoft][ODBC Microsoft Access Driver] 用于函数参数的个数不对 在查询表达式 '(订单数量>isnull(发货总计,0))' 中。
      

  12.   

    select * from table1 where iif(IsNull(a2),0,a2)>iif(IsNull(a4),0,a4)
      

  13.   

    access 应该去access那边问 ...
    函数用法这些都不一样的
      

  14.   

    ACCESS?tryselect * from table1 where IIF(IsNull(a2), 0, a2) > IIF(IsNull(a4), 0, a4);
      

  15.   

    select * from table1 where isnull(a3,0)>isnull(a4,0)
      

  16.   

    更正下select * from table1 where isnull(a2,0)>isnull(a4,0)
      

  17.   

    select * from table1 where IIF(IsNull(a2), 0, a2) > IIF(IsNull(a4), 0, a4);
      

  18.   

    select * from table1 where isnull(a2,0)>isnull(a4,0);
      

  19.   

    sql server 中 不管a2,a4哪个空哪个不空  a2>a4 都没有问题