(無版本資訊,可能僅在 Git 中)
TableSelect::having — 設定 select having 條件
設定在聚合函式運算中要考慮的記錄條件。
sort_expr
關於在分組條件中使用的聚合函式的條件。
一個 TableSelect 物件。
範例 #1 mysql_xdevapi\TableSelect::having() 範例
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 42)")->execute();
$session->sql("INSERT INTO addressbook.names values ('Suki', 31)")->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$result = $table->select('count(*) as count', 'age')
->groupBy('age')->orderBy('age asc')
->having('count > 1')
->execute();
$row = $result->fetchAll();
print_r($row);
?>
以上範例將輸出類似以下的內容:
Array ( [0] => Array ( [count] => 2 [age] => 42 ) )