使用TIMESTAMP数据类型选择特定日期的行 [英] Select rows for a specific date using TIMESTAMP datatype

查看:104
本文介绍了使用TIMESTAMP数据类型选择特定日期的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有以下表格:

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, book_name: string, author: string)
Iss_rec    (iss_no: integer, iss_date: date, Mem_no: string, book_no: string)

我创建了表并插入了以上模式定义的值.我在 iss_date 中使用了 TIMESTAMP ,以便系统自动将当前日期作为 iss_date 的默认值.

I created the tables and inserted values defined by the above schemas. I used TIMESTAMP in the iss_date so that present date is taken by the system automatically as the default value for iss_date.

现在我必须列出所有学生和书名,作者在特定日期(例如06-08-2019)发行.

我写了这个查询:

SELECT student.stud_name, book.book_name, book.author,iss_rec.iss_date
FROM student, book, iss_rec, membership
WHERE student.stud_no = membership.stud_no
AND membership.Mem_no = iss_rec.Mem_no
AND book.book_no = iss_rec.book_no
AND iss_date = '2019-08-06'

但是它什么也没产生!每当我切断最后一行:AND iss_date = '2019-08-06'时,它都会产生一个列表.但是,如前所述,如何获得特定日期的清单? 我不需要小时:分钟:秒,只需要yyyy-mm-dd.

but it yields nothing! Whenever I cut off the last line: AND iss_date = '2019-08-06', it yields a list. But how could I get list for a specific date as I mentioned earlier? I don't want hour:minute:second, only yyyy-mm-dd.

推荐答案

您可以使用DATE函数

AND DATE(iss_date) = '2019-08-06';

这篇关于使用TIMESTAMP数据类型选择特定日期的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆