table1  
字段:BoxCode,CartonCode一个Carton装多个Box ,即1:n现要在table1中找出每个Caron中的一个Box

解决方案 »

  1.   

    select BoxCode,CartonCode
    from table1
    group by BoxCode,CartonCode
      

  2.   

    select
     BoxCode,max(CartonCode)
    from
     table1
    group by
     BoxCode
      

  3.   

    Select max(boxcode),cartoncode
    from tb
    group by cartoncode
      

  4.   

    select BoxCode,CartonCode
    from tb a 
    where BoxCode=(select max(BoxCode) from tb where CartonCode=a.CartonCode)
      

  5.   

    select BoxCode,CartonCode
    from table1
    where exists(select top 1 BoxCode,CartonCode from table1 where CartonCode = A.cartoncode)
    TRY