How to write a query for same Date2 but different Price?

  • NameDate Date2 Price

    A28/01/2011 28/01/2011 10.5039

    A27/01/2011 27/01/2011 10.5175

    A26/01/2011 26/01/2011 10.5001

    B28/01/2011 27/01/2011 10.5009

    B27/01/2011 27/01/2011 10.5172

    B26/01/2011 26/01/2011 10.4601

    C28/01/2011 27/01/2011 10.5109

    C27/01/2011 27/01/2011 10.5177

    C26/01/2011 26/01/2011 10.4751

    I have a table keep data like above, I would like to query for Which name have same Date2 but Different Price? How can I write a query?

  • Join the table to itself on Date2, and on Price doesn't equal Price.

    Something like:

    select *

    from dbo.MyTable as T1

    inner join dbo.MyTable as T2

    on T1.Date2 = T2.Date2

    and T1.Price < T2.Price;

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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