现有一张表名为“工资表",简化为四个字段:日期,薪水1,薪水2,薪水3。 目的是要查出每个月里,每天的最高薪水值 。请问该如何写SQL语句呢?重点不是月份的判断,而是如何横向比较每天的三个薪水值,取出最大值。
在线等待,多谢!!

解决方案 »

  1.   

    to A_ZHU(诸葛祥云) :
      日期是三个薪水公共的,你可以认为它是三个日期字段合成一个字段啊?能请你写出具体的SQL语句吗?多谢!
      

  2.   

    我来写:
    select column1 from table where column1>column2 and column1>column3
    union 
    select column2 from table where column2>column1 and column2>column3
    uniom
    select column3 from table where column3>column2 and column3>column1
      

  3.   

    to hhzqf1980(hh)  : 我先试试你的高招是否可行:)谢谢
      

  4.   

    select *,newex = case
       when (salary1>salary2)and(salary1>salary3) then salary1
       when (salary2>salary1)and(salary2>salary3) then salary2
       when (salary3>salary1)and(salary3>salary2) then salary3
     end
    from table
      

  5.   

    select max(case when data1>data2 then case when data1>data3 then data1 else data3 end  
    else case when data2>data3 then data2 else data3 end end)
    from table2
      

  6.   

    to greeneys(水市) ( )  :正想结帐,既然你来了,再试试你的药方:)
      

  7.   

    to   hqhhh(枫叶) ( ): 又有新方法了?一并试验!
      

  8.   

    hhzqf1980(hh)
     greeneys(水市)
    都可以!
      

  9.   

    呵呵,经过我适当的修改后,三位高手的语句都能查找到我需要的东东,但 greeneys(水市) ( )的条理最清楚,我准备在工程里采用水市的。
    只是这个SQL会超长啊?因为实际情况中,我的表中有十几个字段(三个三个分成一组来比较),而且又要求最大值,又要求最小值 ,不知delphi中SQL语句的长度上限为多少个字符?
      

  10.   

    to  greeneys(水市) : 什么事情真巧啊?  你的方法会不会超过SQL语句长度上限啊?:)