As you're probably aware, the fields are added in via the system fields plugin. When the admin form is being built the event onContentPrepareForm is triggered, and this results in the system fields plugin adding in the custom fields into the form xml structure.
Later in the layout file renderField() is called, and this causes the field structures in the ...
Either I'm editing the wrong bit of code.
This is the answer. The layout (plugins/fields/sql/tmpl/sql.php) is used for displaying the value in frontend, not for rendering the field in forms. You will need to create your own plugin. Either with a custom form field class or with custom code in onCustomFieldsPrepareDom event.
Try to get the user id like this:
$user = JFactory::getUser();
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 ...