diff --git a/src/YesSql.Abstractions/ISqlBuilder.cs b/src/YesSql.Abstractions/ISqlBuilder.cs index 8fde28ed..abad9a0c 100644 --- a/src/YesSql.Abstractions/ISqlBuilder.cs +++ b/src/YesSql.Abstractions/ISqlBuilder.cs @@ -44,5 +44,7 @@ public interface ISqlBuilder IEnumerable GetSelectors(); IEnumerable GetOrders(); void Join(JoinType type, string table, string onTable, string onColumn, string toTable, string toColumn, string schema, string alias = null, string toAlias = null); + void HavingAnd(string having); + void HavingOr(string having); } } diff --git a/src/YesSql.Core/Sql/SqlBuilder.cs b/src/YesSql.Core/Sql/SqlBuilder.cs index b1608f2f..321670f6 100644 --- a/src/YesSql.Core/Sql/SqlBuilder.cs +++ b/src/YesSql.Core/Sql/SqlBuilder.cs @@ -232,6 +232,36 @@ public virtual void WhereAnd(string where) WhereSegments.Add(where); } + public virtual void HavingAnd(string having) + { + if (string.IsNullOrWhiteSpace(having)) + { + return; + } + + if (HavingSegments.Count > 0) + { + HavingSegments.Add(" AND "); + } + + HavingSegments.Add(having); + } + + public virtual void HavingOr(string having) + { + if (string.IsNullOrWhiteSpace(having)) + { + return; + } + + if (HavingSegments.Count > 0) + { + HavingSegments.Add(" OR "); + } + + HavingSegments.Add(having); + } + public bool HasJoin => _join?.Count > 0; @@ -297,14 +327,14 @@ public virtual void ThenOrderByRandom() OrderSegments.Add(_dialect.RandomOrderByClause); } - public virtual void GroupBy(string orderBy) + public virtual void GroupBy(string groupBy) { - GroupSegments.Add(orderBy); + GroupSegments.Add(groupBy); } - public virtual void Having(string orderBy) + public virtual void Having(string having) { - HavingSegments.Add(orderBy); + HavingSegments.Add(having); } public virtual void Trail(string segment)