Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009
    Posts
    4

    Unanswered: finding max difference in a sql..

    EMP & PROJECT columns have many to many relationships.
    Required is to identify Project executed for a maximum time + employee who has worked for the maximum time in a project.

    (Timestamp values when inserted comes as a hexa values.)

    I have no clue of how to accomplish this in a query. Please help.

    EMP_PROJECT table:
    EMP PROJECT TIMESTAMP
    A X Hexa value
    B X Hexa value
    C Y Hexa value
    A Y Hexa value
    D Z Hexa value
    C Z Hexa value


    Thanks.

  2. #2
    Join Date
    Nov 2009
    Posts
    4
    More simple version for the above sql that I can think of is finding the max diff on the salary based on the id. :

    ID SALARY
    1 50
    1 100
    2 50
    2 150
    3 200
    4 500

    Result should look like & in the descending order:

    ID SALDIFF
    2 100
    1 50

  3. #3
    Join Date
    Apr 2008
    Location
    Iasi, Romania
    Posts
    561
    Provided Answers: 2
    Select a.ID, (a.MaxSal - b.MinSal) as SalDiff
    From
    (
    Select ID, Max(Salary) as MaxSal
    From SalTest
    Group By ID
    ) a,
    (
    Select ID, Min(Salary) as MinSal
    From SalTest
    Group By ID
    ) b
    where a.ID = b.ID
    order by SalDiff desc
    Florin Aparaschivei
    DB2 9.7, 10.5 on Windows
    Iasi, Romania

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •