Try to get the user id like this:
$user = JFactory::getUser();
$id= $user->id;
Try to directly add it onto your sql statement:
$query = $fieldParams->get('query', ''); // Run the query with a having condition because it supports aliases $db->setQuery($query . ' AND created_by =' . $db->q('.$id.' ));
also check permissions and everything.
You can try unistalling the plugin.
Fix the database by going to:
Extension > Manage > Database and click "fix".
Manually clean the tables releated to your plugin if there's still leftovers.
Clean the cache.
Verify if all files are there.
Verify if it's the correct database.
Install the plugin again.
PLUS:
Instead of editing
plugins/fields/sql/tmpl/sql.php
try to edit the helper and the view file. Those are responsible for manipulating the database. That's probably the cause of the error you are getting.