create table 订货单表(职工号 char(10),供应商号 char(10),订购单号 char(10))
insert into 订货单表 values('e3','s7','or67')
insert into 订货单表 values('e1','s4','or73')
insert into 订货单表 values('e7','s4','or76')
insert into 订货单表 values('e6','','or77')
insert into 订货单表 values('e3','s4','or79')
insert into 订货单表 values('e1','','or80')
insert into 订货单表 values('e3','','or90')
insert into 订货单表 values('e3','s3','or91')alter table 订货单表 add 总金额 int 
update 订货单表
set 总金额=20000 where 订购单号='or67'
update 订货单表
set 总金额=30000 where 订购单号='or73'
update 订货单表
set 总金额=10000 where 订购单号='or76'
update 订货单表
set 总金额=560000 where 订购单号='or77'
update 订货单表
set 总金额=240000 where 订购单号='or79'
update 订货单表
set 总金额=203000 where 订购单号='or80'
update 订货单表
set 总金额=200400 where 订购单号='or90'
update 订货单表
set 总金额=23400 where 订购单号='or91'--列出每个职工经手的具有最高总金额的订购单信息.

解决方案 »

  1.   

    select 职工号, max(总金额) from 订货单表 group by 职工号
      

  2.   

    select 职工号, max(总金额) from 订货单表 group by 职工号
      

  3.   

    select * from (
      select 订货单表.*, row_number() over(partition by 职工号 order by 总金额 desc) row from 订货单表
    ) where row=1
      

  4.   

    select * from 订货单表 a,(select 职工号,max(总金额) 总金额 from 订货单表 group by 职工号) b
    where a.职工号=b.职工号 and a.总金额=b.总金额;
      

  5.   


    这是对的,你试试看.
    这样也可以.
    select 职工号, max(总金额) from 订货单表 group by 职工号
    select * from 订货单表 where 总金额 in (select max(总金额) from 订货单表 group by 职工号 )还有最好数据库不要用中文字段哦!