如下图,表名称为agentlist,字段agent中有些数据是重复的,我想在一页面中显示agent中不重复的数据,排序就按GP的字段总和从大到小的排序。请问SQL语句怎么写?
select distinct agent,sum(GP) as gp from agentlist order by gp desc
select distinct agent,sum(GP) as gp from agentlist order by gp desc
from agentlist
group by agent
order by gp desc
select agent,sum(GP) as gp from agentlist
group by agent order by gp desc
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
select agent, --无需distinct
sum(GP) as gp
from agentlist
group by agent --少group by
order by gp desc
不知道 你不是这个意思,select agent,sum(GP) as GP from m_agentlist group by agent having(count(*)=1) order by GP desc
-- agent 维一 同时输出gp的值!!