Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何在定期更新数据的过程中获得不大于给定日期范围的准确数据_Mysql_Sql_Sql Server_Database_Sql Server 2008 - Fatal编程技术网

Mysql 如何在定期更新数据的过程中获得不大于给定日期范围的准确数据

Mysql 如何在定期更新数据的过程中获得不大于给定日期范围的准确数据,mysql,sql,sql-server,database,sql-server-2008,Mysql,Sql,Sql Server,Database,Sql Server 2008,我有一个数据库,有一些单位定期报告。我想要一个查询,在那里我可以看到在某个日期之后没有登录的单位 select distinct FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleName from FSS_LIVE_50.dbo.AgencyVehicle inner join FSS_LIVE_50.dbo.VehicleLocation on FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleKey = FSS_LIV

我有一个数据库,有一些单位定期报告。我想要一个查询,在那里我可以看到在某个日期之后没有登录的单位

select distinct FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleName from FSS_LIVE_50.dbo.AgencyVehicle
inner join FSS_LIVE_50.dbo.VehicleLocation
on FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleKey = FSS_LIVE_50.dbo.VehicleLocation.AgencyVehicleKey
where FSS_LIVE_50.dbo.VehicleLocation.GPSLocationDate < '2013-01-01'
and FSS_LIVE_50.dbo.AgencyVehicle.TermDate is NULL
order by AgencyVehicleName
现在它向我展示了2013-01-01之后也有日志的车辆,因为它们在该日期之前和之后都有日志

如何从显示中排除在此之后还有日期日志的名称>?

将distinct更改为group by。然后添加having子句。您正在寻找截止日期之前的最大日期:

select FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleName
from FSS_LIVE_50.dbo.AgencyVehicle inner join
     FSS_LIVE_50.dbo.VehicleLocation
     on FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleKey = FSS_LIVE_50.dbo.VehicleLocation.AgencyVehicleKey
where FSS_LIVE_50.dbo.AgencyVehicle.TermDate is NULL
group by FSS_LIVE_50.dbo.AgencyVehicle.AgencyVehicleName
having MAX(FSS_LIVE_50.dbo.VehicleLocation.GPSLocationDate) < '2013-01-01'
order by AgencyVehicleName;

明智地使用别名也会使您的查询更具可读性。

请更正大写文本-使用正确的大小写。