如下图,表名称为agentlist,字段agent中有些数据是重复的,我想在一页面中显示agent中不重复的数据,排序就按GP的字段总和从大到小的排序。请问SQL语句怎么写?
select distinct agent,sum(GP) as gp from agentlist order by gp desc

解决方案 »

  1.   

    select distinct agent,sum(GP) as gp
    from agentlist 
    group by agent
    order by gp desc
      

  2.   

    select agent,sum(GP) as gp from agentlist group by agent order by gp desc
      

  3.   

    select agent,sum(GP) as gp from agentlist group by agent order by gp desc
      

  4.   


    select agent,sum(GP) as gp from agentlist
    group by agent order by gp desc
      

  5.   


    select agent , sum(gp) from
    (
      select t.* from agentlist t where pid = (select min(pid) from agentlist where agent = t.agent)
    ) m
    group by agentselect agent , sum(gp) from
    (
      select t.* from agentlist t where not exists (select 1 from agentlist where agent = t.agent and pid < t.pid)
    ) m
    group by agent
      

  6.   


    select agent,   --无需distinct
           sum(GP) as gp 
    from agentlist 
    group by agent  --少group by
    order by gp desc
      

  7.   

    貌似我理解错了?select agent , sum(gp) gp from agentlist t group by agent order by gp desc
      

  8.   

    agent中不重复的数据  Gp 不就是一个值么?排序就按GP的字段总和从大到小的排序??
    不知道 你不是这个意思,select agent,sum(GP) as GP from m_agentlist group by agent having(count(*)=1) order by GP desc
    --  agent 维一  同时输出gp的值!!