select top 1 month,plate,proto,subtitle,product_code,type  from PRODUCT_TABLE where product_code='1100310' order by PRODUCT_CODE,type DESC

解决方案 »

  1.   

    select top 1 month,plate,proto,subtitle,product_code,type  from PRODUCT_TABLE where product_code='1100310' order by PRODUCT_CODE,type DESC
      

  2.   

    select month,plate,proto_num,subtitle,product_code,type  from PRODUCT_TABLE where plate='0000'order by PRODUCT_CODE,type DESC  
    如果我有这样的记录
    month    plate    proto_num  subtitle        product_code  type 
    03031 0000 103250401  303250401100 1100310 303250402103195
    03031 0000 103180601  303180601100 1100310 303180602103195
    03031 0000 103195  103031042999 1100310 0
    03031 0000 1030226801 00 1100311 0
    02021 0000 102030361  302040361100 1100311 11100310
    02021 0000 1030115801 00 1100312 502040361102040361
    02121 0000 112260941  312260941100 1100312 11100310
    02101 0000 110120771  310120771100 1100314 11100x01
    02101 0000 110120772  310120771100 1100314 11100x01
    我要取product_code不相同的记录,又怎么做?
    也就是说要得到的结果有4个,如:
    month    plate    proto_num  subtitle        product_code  type 
    03031 0000 103250401  303250401100 1100310 303250402103195
    02021 0000 102030361  302040361100 1100311 11100310
    02021 0000 1030115801 00 1100312 502040361102040361
    02101 0000 110120771  310120771100 1100314 11100x01怎么写?
      

  3.   

    product_code 如果有一列自动号列如: ID 则:
    select *
    from PRODUCT_TABLE T
    where [ID] = (Select max([id]) from PRODUCT_TABLE where T.product_code = product_code)
    select *
    from PRODUCT_TABLE T
    where [ID] in (Select top 1 [id] from PRODUCT_TABLE where T.product_code = product_code)
      

  4.   

    我这个表里没有自动编号的,product_code只是关键字之一,现在我想用
    select * from PRODUCT_TABLE where plate='0000'order by PRODUCT_CODE,type DESC 
    来实现我要找的记录,原来是在程序中实现的,现在想优化