2

I have one table with name tblprop and data:

houseid | date      |

--------+------------

 1      | 2014-10-10|

and another table with name tbltrans and data:

transno |houseid | transdate    |

--------+-------- +--------------

 1      |   1     |2014-10-20   |

I want a query that calculates the difference between date of tblprop and transdate of tbltrans and the result is in terms of days.

result is like this:

houseid | difference|

--------+------------

 1      | 10days    |

Thanks and more power.

1 Answer 1

1

Just subtract them. As both are dates the result of the difference is the number of days.

select p.houseid,
       t.transdate - p.date
from tblprop p
  join tbltrans t on t.houseid = p.houseid;

If both were timestamp columns you'd get back an interval (rather than an integer representing days)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.