如题,如何在页面上显示这个记录集的最后一条记录呢?语句如下:
SELECT isnull(c.title,'总计') xiangmu,      sum(isnull(p.score,0)) blzf,      sum(isnull(q.score,0)) bldf  from      classlist c  left join      (select            n.class,sum(score) as score        from            news n,answer a        where            n.id=a.stid and not exists(select 1 from answer where stid=a.stid and score>a.score)        group by n.class) p  on      c.id=p.class  left join      (select class,sum(score) as score
FROM grade  WHERE username='varuser' group by class) q  on      c.id=q.class
WHERE c.depth<>0 group by      c.title with rollup
我想显示的是总计对应的blzf和bldf.

解决方案 »

  1.   

    将你的sql来一个DesC,然后加一个Top 1
      

  2.   

    select top 1 p.* from (SELECT isnull(c.title,'总计') xiangmu,      sum(isnull(p.score,0)) blzf,      sum(isnull(q.score,0)) bldf  from      classlist c  left join      (select            n.class,sum(score) as score        from            news n,answer a        where            n.id=a.stid and not exists(select 1 from answer where stid=a.stid and score>a.score)        group by n.class) p  on      c.id=p.class  left join      (select class,sum(score) as score
    FROM grade  WHERE username='varuser' group by class) q  on      c.id=q.class
    WHERE c.depth<>0 group by      c.title with rollup) p order by '排序字段?' desc
      

  3.   

    楼主好像不是这个意思吧?是只要总计的结果吧。直接select sum()不行吗?