Tip
All examples used are valid against the Microsoft Northwind Sample Database You can run the resulting SQL from the examples against Northwind in order to test and play with the SqlObjects library.
HAVINGΒΆ
Basic Syntax
var sql = TSQL
.SELECT()
.COLUMN("c", "CategoryName")
.COUNT("p", "ProductID").AS("TotalProducts")
.AVG("p", "UnitPrice").AS("AvgPrice")
.FROM("dbo", "Products", "p")
.INNERJOIN("dbo", "Categories", "c").ON("c", "CategoryID").IsEqualTo("p", "CategoryID")
.GROUPBY()
.HAVING()
.AVG("p", "UnitPrice").IsGreaterThan(25.00m)
.Build()
;
Console.WriteLine(sql);
Output:
SELECT
[c].[CategoryName],
COUNT([p].[ProductID]) AS [TotalProducts],
AVG([p].[UnitPrice]) AS [AvgPrice]
FROM [dbo].[Products] p
INNER JOIN [dbo].[Categories] c ON [c].[CategoryID] = [p].[CategoryID]
GROUP BY
[c].[CategoryName]
HAVING 1=1
AND AVG([p].[UnitPrice]) > 25.00
Conditions
Conditions in a HAVING
clause are the same as those in a WHERE
clause. You can find the syntax for those
concerns by clicking on the links below.