You can do this with the expression builder in Select by Expression.
Assuming your date is in a date format, try the following:
"duplicates" = 1 and "date" < to_date(maximum("date","number","number"="number"))
This should select all features where there is a duplicate and the date is less than the latest one for that house number.
However a faster calculation may be to select only the houses that have the latest date (which will include features where there are no duplicates):
"date" = to_date(maximum("date","number","number"="number"))
And then invert the feature selection.
If the above doesn't work as expected try removing the to_date()
or also wrapping it around "date"
in the beginning.
The maximum()
aggregate function used with grouping and filtering arguments in QGIS's expression builder works much like max()
with GROUP BY
in SQL. In this case it groups all the records by house number, finds the maximum date for each house number, and then goes through the list of features and returns that maximum date for that house number (not the maximum date of all records!)
Please note you have to use maximum()
in the expression builder and not max()
(which is not an aggregate function).
I have tested this out in QGIS 3.4.