select ProductType_T from T_ProductType group by ProductType_T 怎么才能用order by 通过ProductType_ID 排列呢? 急谢谢!!在线等。

解决方案 »

  1.   

    order by 是根据某个字段进行排序,而Group by是根据某个字段进行分类吧!~~
      

  2.   

    是的,我是想通过ProductType_T字段进行分组后,在通过ProductType_ID进行排序!
      

  3.   

    select lngComputerID from Computers group by lngComputerID
    order by lngComputerID
    你的不是对的吗?
      

  4.   

    你查一下T-SQL语法就行了,应该有的,很具体的
      

  5.   

    select lngComputerID from Computers group by lngComputerID
    order by lngComputerID
    这个是对的啊!~~
      

  6.   

    select ProductType_T from T_ProductType group by ProductType_T order by ProductType_ID
      

  7.   

    select ProductType_T from T_ProductType group by ProductType_T order by ProductType_ID这句话找不出记录了,去掉 order by ProductType_ID 是可以找出记录的
      

  8.   

    试试这个:select Computer_name,max(lngComputerID) from Computers group by Computer_name,lngComputerID
    order by lngComputerID
      

  9.   

    sorry ! 应该是这个select Computer_name,max(lngComputerID) as lngComputerID from Computers group by Computer_name,lngComputerID
    order by Computer_name,lngComputerID
      

  10.   

    ......这么多人回复,怎么没有懂的?select ProductType_T from T_ProductType group by ProductType_T order by ProductType_ID这种句子是错误的!!ProductType_ID 没包含在group by语句中,是不行的!
      

  11.   

    to downmoon(邀月) :
    lngComputerID 是自动编号的,也就是说没有重复的,因此,要是同时按照lngComputerID分组的话,那就出现检索的数据重复出现!我昨天晚上也试过,就是这个效果!
      

  12.   

    select ProductType_T,ProductType_ID from T_ProductType group by ProductType_T,ProductType_ID order by ProductType_ID
    试试这个。
      

  13.   

    select (select ProductType_T from T_ProductType group by ProductType_T) from  T_ProductType order by ProductType_ID
      

  14.   

    晕,怎么都没回到点子上楼主知道select ProductType_T from T_ProductType group by ProductType_T order by ProductType_ID这句为什么是错的么?因为group by分组是把某字段相同的记录合并,但是ProductType_T相同并不意味着ProductType_ID就相同,所以加一个order by ProductType_ID的话,SQL分析器根本不知道是用哪个ProductType_ID来排序。加上聚合函数就OK了,如下:select ProductType_T from T_ProductType group by ProductType_T order by max(ProductType_ID)或者select ProductType_T from T_ProductType group by ProductType_T order by min(ProductType_ID)
      

  15.   

    select ProductType_T
    from T_ProductType 
    group by ProductType_T,ProductType_ID 
    order by ProductType_IDid只需要出现在聚合函数中或group by子句中就可以了。
      

  16.   

    to liuqinglq(白菜) :对对对,谢谢你的提醒!!!真的感谢你!
      

  17.   

    谢谢liuqinglq(白菜),散分了~~~