Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a cron job to expire legislators #38

Open
waldoj opened this issue Jan 6, 2018 · 1 comment
Open

Create a cron job to expire legislators #38

waldoj opened this issue Jan 6, 2018 · 1 comment

Comments

@waldoj
Copy link
Member

waldoj commented Jan 6, 2018

As a hedge against errors, find any legislator who has the same district ID as another one and expire the older of the two legislators, setting date_ended to the day prior to the new legislator's date_started.

@waldoj
Copy link
Member Author

waldoj commented Jan 15, 2018

Something like this may do it. This gets a list of every legislator whose date_ended is null, whose record was created more than 10 days ago, and who shares a district ID with a legislator whose record was created less than 10 days ago.

SELECT r1.name, r1.id
FROM representatives AS r1
WHERE r1.date_ended IS NULL AND r1.date_created < NOW() - INTERVAL 10 DAY AND r1.district_id=
	(SELECT r2.district_id
     FROM representatives AS r2
     WHERE r2.district_id=r1.district_id
     AND date_created BETWEEN CURDATE() - INTERVAL 10 DAY AND CURDATE())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant