mysql - How to get accurate data for a date range not greater than a given one in a periodically updating data -


i have database has units report in @ regular intervals. want query can see units have not logged after date.

select distinct fss_live_50.dbo.agencyvehicle.agencyvehiclename 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 fss_live_50.dbo.vehiclelocation.gpslocationdate < '2013-01-01' , fss_live_50.dbo.agencyvehicle.termdate null order agencyvehiclename 

now shows me vehicles have logs after "2013-01-01", because have logs before , after date

how can exclude names being shown have date logs after >?

change distinct group by. add having clause. looking largest date being before cutoff:

select fss_live_50.dbo.agencyvehicle.agencyvehiclename 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 fss_live_50.dbo.agencyvehicle.termdate null group fss_live_50.dbo.agencyvehicle.agencyvehiclename having max(fss_live_50.dbo.vehiclelocation.gpslocationdate) < '2013-01-01' order agencyvehiclename; 

judicious use of aliases make query more readable.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -