select id,bid,cid from group by id,bid,cid,did ordey by did desc为什么分group by 分组的时候 只要在SQL中出现的列 group后面都要写上?
为什么。我只想按id分组。。应该只取出1条。如果我加上bid。cid就会取出50条。如何解决

解决方案 »

  1.   

    select
     *
    from
     tb t
    where
     id=(select min(id) from tb where bid=t.bid and cid=t.cid)
      

  2.   

    select * from tb t 
    where not exists(select 1 from tb where id=t.id and bid>t.bid or (bid=t.bid and cid>t.cid))
      

  3.   

    晕,分组肯定啦,要全部分
    select id,MAX(bid),MAX(cid),MAX(DID) from group by id ORDER by MAX(DID) desc
      

  4.   

    select 中的列只能比group 中的列多一列,且这一列要用聚合函数
      

  5.   

    你想一想吧,
    A-B--C
    1-2--2
    1-3--3
    你要统计B按A分组,统计后是1--5要是你来个C,C怎么办,他不知道C最后是哪个了吧