select cus_id,cus_name,inputdate,qty,amt from table a where not exists(select 1 from table where a.inputdate>inputdate)

解决方案 »

  1.   


    select cus_id,cus_name,inputdate,qty,amt from table1 
    where inputdate in (select min(inputdate) from table1)
      

  2.   

    select 
           * 
    from 
           表 t
    where 
          not exists(
                     select 1 
                     from 表
                     where inputdate<t.inputdate
                     )
      

  3.   

    select 
           * 
    from 
           表 t
    where 
          not exists(
                     select 1 
                     from 表
                     where inputdate<t.inputdate
                     )
      

  4.   

    select * from(
    select c.customer_id,c.customer_name,a.inputdate,sum(qty) as qty,sum(discountamt) as amt
    from transactionhead a inner join transactionlist b on a.transid = b.transid inner join customer c on a.customer_id = c.customer_id
    where a.transname = '出庫'
    group by c.customer_id,c.customer_name,a.inputdate
    ) x
    一条这样的语句想要取出每一个customer_id所对应最小日期的纪录
    刚才说的测试没有结果
      

  5.   

    数字
    其实不管是1还是什么别的都没有关系。
    主要是有个exists存在where not exists(……)
    意思是当不存在……(只要查出来的没有1条记录就是不存在,反之则是存在,当然是不会去管查出来的是什么,只判断有没有记录)
      

  6.   

    select c.customer_id,c.customer_name,a.inputdate,sum(qty) as qty,sum(discountamt) as amt
    from transactionhead a inner join transactionlist b on a.transid = b.transid inner join customer c on a.customer_id = c.customer_id
    where a.transname = '出庫'
    group by c.customer_id,c.customer_name,a.inputdate
    我把上面的语句创建了一个view叫v123
    然后在查询分析器中写
    select * from v123  x
    where not exists (select 1 from v123 where inputdate < x.inputdate)
    点击parse query提示成功,点击execute query就没有任何反映了
    再点击cancel query execution提示
    Query cancelled by User
    [Microsoft][ODBC SQL Server Driver]Operation canceled
    这不是表中有没有数据的问题吧
    帮忙继续解决一下
      

  7.   

    是不是这个意思
    select * from tb where inputdate in( select min(inputdate) from tb )