Select rows for a specific date using TIMESTAMP datatype

后端 未结 3 388
温柔的废话
温柔的废话 2021-01-27 09:51

I have the tables below in my database:

Student    (Stud_no: string, Stud_name: string)
Membership (Mem_no: string, Stud_no: string)
Book       (book_no: string,         


        
相关标签:
3条回答
  • 2021-01-27 10:19

    Note that we stopped writing queries this way ca. 1992. Come. Join us.

    FWIW, I find this easier to read...

    SELECT s.stud_name
         , b.book_name
         , b.author
         , r.iss_date
      FROM student s
      JOIN membership m
        ON m.stud_no = s.stud_no 
      JOIN iss_rec r 
        ON r.Mem_no = m.Mem_no 
      JOIN book b
        ON b.book_no = r.book_no
     WHERE r.iss_date BETWEEN '2019-08-06 00:00:00' AND '2019-08-06 23:59:59';
    
    0 讨论(0)
  • 2021-01-27 10:27

    Just write you query as:

    AND iss_date >= '2019-08-06'
    AND iss_date <  '2019-08-07'
    

    Or more conveniently:

    AND iss_date >= '2019-08-06'
    AND iss_date <  '2019-08-06' + INTERVAL 1 DAY
    

    While this looks lengthy, it can use indexes more efficiently and very generic.

    0 讨论(0)
  • 2021-01-27 10:34

    You can use DATE function

    AND DATE(iss_date) = '2019-08-06';
    
    0 讨论(0)
提交回复
热议问题