Limit the results returned by 'published'
The node table has a field called status - 1 is published, 0 is unpublished.

Are field_test_2004 and field_test_2005 Drupal generated tables?

Normally table names take the form of field_data_field_test_2004...

Anyway, assuming they are Drupal generated tables they will have a field called entity_id which you can join to the node table with.

If you are building queries like this I would suggest you look into using Drupal Dynamic Queries as opposed to string concatenation - it is much easier to add bits to and manipulate the query.

Also feilds is spelt fields (sorry, couldn't help myself)