SQL SQL如何显示某个日期之前的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15456676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:18:28  来源:igfitidea点击:

SQL How to display data before a certain date

sqldate

提问by user2172295

I have a couple of tables. One is a worker tablewhich displays worker code, firstname and lastname. Job dateswhich shows worker code, date of job start, end and job area code. Supervisorhas worker number, firstname, surname and job area code. Job areahas job area code name and supervisor.

我有几张桌子。一个是显示工人代码、名字和姓氏的工人表工作日期,这说明工人代码,工作的开始日期,结束和工作区号。 主管有工人编号、名字、姓氏和工作区号。 工作区域有工作区域代码名称和主管。

What I'm trying to do is display the worker code before date 10/09/10 Since I am new to this, I'm trying to do it all written and theory first before making the database.

我想要做的是在 10 年 9 月 10 日之前显示工作人员代码,因为我是新手,所以在创建数据库之前,我试图首先完成所有书面和理论工作。

Does this sound right? I'm not too sure about the date thing.

这听起来对吗?我不太确定日期的事情。

select worker
From Job Dates
where job start < '10/09/10'

In theory this sounds right to me, but does it somehow need to tell the query it is a date stamp?

理论上这对我来说听起来是对的,但它是否需要以某种方式告诉查询它是一个日期戳?

I then want to find the surname of workers and the surnames of their supervisor if the workers started the job before the 10/09/10? I'm guessing this will be with a JOIN?

如果工人在 10/09/10 之前开始工作,我想找到工人的姓氏和他们主管的姓氏?我猜这将与 JOIN 一起使用?

Thanks

谢谢

回答by Hyman Marchetti

You're on the right track. Not knowing the schema of your database, your ultimate query will look something like this:

你在正确的轨道上。不知道您的数据库的架构,您的最终查询将如下所示:

select w.surname, s.surname
From worker w INNER JOIN JobDatesTable jdt on w.id = jdt.id
              INNER JOIN SuperVisor s on w.id = s.id
where jdt.jobstart < '20101009'