it-swarm.com.de

Fügen Sie den Ausdruck db_select hinzu

Was ist die entsprechende Alternative in Drupal 7 für die folgende Abfrage

SELECT row_id,name,email, COUNT(name) AS name_count
FROM tn_api_users 
GROUP BY name
HAVING  (name_count > 1)
6
Oleg Videnov

Das würde eine Kombination von SelectQuery::addExpression() und SelectQuery::having() erfordern, z.

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

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

Ausgabe:

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 > 1)
6
Clive