sql1:"select..." 它返回的结果如下:
id  count 
1    10
2    20
3    30
4    40
我现在想对count求最大值,然后对应每个ID,对sql1查询1次,怎么写??得到如下结果:
id  count max
1    10   40
2    20   40
3    30   40
4    40   40

解决方案 »

  1.   

    select a.* ,b.* from
    table1 a,
    (select max(t.count) from table1) b
      

  2.   

    select a.* ,b.* from 
    table1 a, 
    (select max(t.count) from table1 t) b忘记给表取别名了
      

  3.   

    select id,count,max(count) over() max from table
      

  4.   

    select zz.*,
           max(count) over() as "max_count"
      from (
            select tt.id,
                   count(*) as "count"
              from tablename tt
             group by tt.id
            )zz;
      

  5.   

    select id,count,max(count) over() max from table
      

  6.   


      select distinct dd.d1,dd.d2,max(t.count) over() 
      from demo t
      inner join ( select d.id d1,sum(d.count) d2
      from demo d group by d.id) dd on dd.d1=t.id
      order by dd.d1