SQL Q

  • I'm new here, so i this is in the wrong forum I apologize.

    Question:

    Let's say I have two columns. A date, and a number that can repeat itself. If I want the earliest date for the last time entering somenum 1. How do I write that in SQL? I've thrown analytical functions, group bys, havings, you name it at it.

    Eg.

    date,somenum

    '08/05/2008',1

    '08/06/2008',1

    '08/07/2008',1

    '08/08/2008',2

    '08/09/2008',2

    '08/10/2008',1

    '08/11/2008',1

    I need 8/10/2008. In other words, the first date for the last time we were at somenum 1.

    I want to do this in a select. No loops or cursors.

    Any ideas?

  • You probably need code like

    SELECT somenum, min (date)

    from yourtable

    group by somenum

  • for the last time entering somenum 1

    Please clarify

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply