Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007

    Unanswered: pick a data based on the data from another column

    Hi All

    Does any know how to pick a value of a column based on the value of another column?

    I have the following table

    id, phone, Order, shipped, date, miniumn
    2, 111-2345, 12, 2, Jan12,2009, 0
    3, 111-2345, 100, 5, Jan15,2009, 10
    4, 222-3456, 23, 1, Feb12,2009, 1
    5, 222-3456, 10, 2, Mar12,2009, 2

    I wants to pick the value from the "Order" column based on the latest date from the "Date" column. At the same time, I need to sum of "shipped" column and picked the grouped records that have the value in the "minimum" column equlas to 0

    That is, I wants to get the result like the following based on the data above.
    phone, order, shipped, minimum
    111-2345, 100, 7, 0

    I tried to use group by and having but I am getting syntax error
    select, phone, order, sum(shipped), minimum from Test group by phone having date = max(date) and minimum = min(minimum)

    I don't really know what to do anymore. Could someone please give me some advice.

    Much Appreciated

  2. #2
    Join Date
    May 2005
    South Africa
    Provided Answers: 1
    select, a.Ordr, b.shp, minium=0 from datable a
    select phone,shp=sum(shipped), dt=max(date)
    from datable
    group by phone
    having min(miniumn)=0
    )b on

Posting Permissions

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