sql数据库,有表table1,
字段:
直径有一个变量intA,是输入获取的。现在要取得直径中 小于这个intA的最大值 的记录。sql语句应该怎么写?我用过order by 排序,但是结果不对。

解决方案 »

  1.   

    select max(直径)
    from table1
    where 直径<intA
      

  2.   

    我想得到这条记录,而不仅仅是直径。
    select max(直径),字段2,字段3
    from table1
    where 直径<intA结果不行呀。
      

  3.   

    试试
    select top 1 *
    from table1
    where 直径<intA 
    order by 直径 DESC
      

  4.   

    多字段啊,我还以为只取一个记录呢。看看这个:
    select 直径,字段2,字段3 
    from table1 
    where 直径=(select max(直径) from (select * from table1 where 直径<intA) a)