How to get fetchField using db_query?
You could achieve this by either one of the following:

By using db_query():

function custom_get_user_account_id() {
    global $user;
    return db_query('SELECT field_account_target_id FROM {field_data_field_account} WHERE entity_id = :user_id AND bundle = :bundle', [
        ':user_id' =&gt; $user-&gt;uid,
        ':bundle' =&gt; 'user',
    ])-&gt;fetchField();
}


Or by using db_select():

function custom_get_user_account_id() {
    global $user;
    return db_select('field_data_field_account', 'fa')
        -&gt;fields('fa', ['field_account_target_id'])
        -&gt;condition('entity_id', $user-&gt;uid)
        -&gt;condition('bundle', 'user')
        -&gt;execute()-&gt;fetchField();
}