CodePudding user response:
Where before the group is limited, if does not meet the conditions, do not participate in the group, having qualified after the grouping, if not satisfied results, will not be queried,CodePudding user response:
After the where can not with aggregate functions, having to aggregate function of judgment,CodePudding user response:
Where the query conditionHaving is in the aggregate functions when using the query condition
https://docs.microsoft.com/zh-cn/sql/t-sql/queries/where-transact-sql? View=SQL server - ver15
https://docs.microsoft.com/zh-cn/sql/t-sql/queries/select-having-transact-sql? View=SQL server -- ver15
CodePudding user response:
Where: filter used in the query result set, such asSelect *
The from [table name]
Where name='zhang' - & gt; The query name is equal to the 'zhang' record
The result set after having: used to group by filtering, such as
Select the name, count (1)
The from [table name]
Group by name - & gt; According to the grouping name
Having a count (1) & gt; 1 - & gt; The grouping of query name same number greater than 1