在做查询功能的时候遇到一个难题:
现在在dbgrid中要显示四个字段分别为'数量1','数量2','数量3','比较结果',其中数量1,2,3可以从表中查出,但'比较结果'需要对数量1,2,3进行比较后得到,如果相同则自动填'相同',反之填'不相同',请问查询怎么写?请高手指点!

解决方案 »

  1.   

    IIf(数量1 > 0, IIF(数量2>0, '相等'), '大于')
      

  2.   

    select 数量1 ,数量2,数量3,
      case  when 数量1=数量2     then '数量1与数量2相同'   
            when 数量1=数量3     then ‘数量1与数量2相同’
            when ...
            else ...
            end as 比较结果
      

  3.   

    select 数量1 ,数量2,数量3,
      case  when 数量1=数量2     then '数量1与数量2相同'   
            when 数量1=数量3     then ‘数量1与数量2相同’
            when ...
            else ...
            end as 比较结果
    from tablename
      

  4.   

    select 数量1,数量2,数量3,
           Case when 数量1=数量2 and 数量2=数量3 then '相同'
                else '不相同'
           End as 比较结果
    from 表名
      

  5.   

    select 数量1 ,数量2,数量3,
    (case when (数量1=数量2 and 数量1=数量3) else '不相同' end) as 比较结果
      

  6.   

    case when 数量1=数量2 =数量3 then '相等' else '不相等' end as '比较结果'