File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ class QueryBuilder
4646 */
4747 public $ groupBy ;
4848
49+ /**
50+ * @var string having часть (условие для данных агрегированных group by)
51+ */
52+ public $ having ;
53+
4954 /**
5055 * @var string поля сортировки
5156 */
@@ -231,6 +236,18 @@ public function groupBy(string $columns)
231236 return $ this ;
232237 }
233238
239+ /**
240+ * Установка HAVING.
241+ * @param string having часть
242+ * @return self
243+ */
244+ public function having (string $ having , array $ values = [])
245+ {
246+ if (!empty ($ this ->having )) $ this ->having .= ' ' ;
247+ $ this ->having .= $ having ;
248+ return $ this ->bindValues ($ values );
249+ }
250+
234251 /**
235252 * Установка ORDER BY.
236253 * @param string столбцы сортировки
@@ -281,6 +298,9 @@ public function getSql(): string
281298 }
282299 if (!empty ($ this ->groupBy )) {
283300 $ sql .= ' GROUP BY ' . $ this ->groupBy ;
301+ if (!empty ($ this ->having )) {
302+ $ sql .= ' HAVING ' . $ this ->having ;
303+ }
284304 }
285305 if (!empty ($ this ->orderBy )) {
286306 $ sql .= ' ORDER BY ' . $ this ->orderBy ;
You can’t perform that action at this time.
0 commit comments