有一个table有a1,a2,a3,a4等4个integer型字段,现要求: 
如何用max这个函数在一条SQL语句中求出四个字段的公共的最大值. select max(x) from 
(select a1 x from table 
 union 
 select a2 x from table 
 union 
 select a3 x from table 
 union 
 select a4 x from table) 好象行是行﹐就是又笨又慢﹐ 
有更好的嗎﹖

解决方案 »

  1.   

    偶不是高手,但这样是不是能比上面的快一点儿
    select max(x)
    from (select max(a1) as x from table
          union
          select max(a2) as x from table
          union
          select max(a3) as x from table
          union
          select max(a4) as x from table
    )
      

  2.   

    select max(x) from 
    (select max(a1) x from table 
     union 
     select max(a2) x from table 
     union 
     select max(a3) x from table 
     union 
     select max(a4) x from table)
      

  3.   

    偶简单做了一下测试PC:  P4 2.4 
    DB:  access 2000
    记录条数:229700使用第一种方法3,4秒
    使用第二种方法1,2秒靠,这么快,是不是我的测试数据太单一了?