Add expression db_select What is the corresponding alternative in Drupal 7 for the following query 

SELECT row_id,name,email, COUNT(name) AS name_count
FROM tn_api_users 
GROUP BY name
HAVING  (name_count &gt; 1)
That would need a combination of SelectQuery::addExpression(), and SelectQuery::having(), e.g.

$query = db_select('tn_api_users', 'u')
  -&gt;fields('u', array('row_id', 'name', 'email'))
  -&gt;groupBy('name')
  -&gt;having('name_count &gt; 1');

$query-&gt;addExpression('COUNT(name)', 'name_count');


Output:

SELECT u.row_id AS row_id, u.name AS name, u.email AS email, COUNT(name) AS name_count
FROM 
{tn_api_users} u
GROUP BY name
HAVING  (name_count &gt; 1)