question

adi121 avatar image
adi121 asked

return first date and previous dates

there is a custid with 3 dates . I want to return first date and then its previous date .

data should look like:

custid first previous

11 2019-06-10 2019-06-15

11 2019-06-10 2019-07-10

i have done it but im not able to put it in 2nd row.

SELECT A.PersonID ,min(a.date) as first,b.date as previous,c.date as previous from Persons as a INNER JOIN (select PersonID ,date from Persons) b on a.PersonID =b.PersonID AND a.date< b.date INNER JOIN (select PersonID ,date from Persons) c on b.PersonID= c.PersonID AND b.date< c.date

output which im getting:

personid first previous previous

11 2019-06-10 2019-06-15 2019-07-10

i want it to look like:

custid first previous

11 2019-06-10 2019-06-15

11 2019-06-10 2019-07-10

Please help..

sqlsql-server
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.