Getting results between two dates in PostgreSQL

前端 未结 8 1596
感动是毒
感动是毒 2020-12-07 22:59

I have the following table:

+-----------+-----------+------------+----------+
| id        | user_id   | start_date | end_date |
| (integer) | (integer) | (da         


        
8条回答
  •  情深已故
    2020-12-07 23:21

    No offense but to check for performance of sql I executed some of the above mentioned solutiona pgsql.

    Let me share you Statistics of top 3 solution approaches that I come across.

    1) Took : 1.58 MS Avg

    2) Took : 2.87 MS Avg

    3) Took : 3.95 MS Avg

    Now try this :

     SELECT * FROM table WHERE DATE_TRUNC('day', date ) >= Start Date AND DATE_TRUNC('day', date ) <= End Date
    

    Now this solution took : 1.61 Avg.

    And best solution is 1st that suggested by marco-mariani

提交回复
热议问题