Two reasons of using Having clause
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;
Ex.
This will execute
select count(id), max(cast(isactive as varchar(2))) from tb_city
where regionid > 2
group by regionid
Syntax error
select count(id), max(cast(isactive as varchar(2))) from tb_city
group by regionid
where regionid > 2
- Can't use 'Where' on records filtered by 'Group by'
- Aggregate functions can't be used in where clause
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value;
Ex.
This will execute
select count(id), max(cast(isactive as varchar(2))) from tb_city
where regionid > 2
group by regionid
Syntax error
select count(id), max(cast(isactive as varchar(2))) from tb_city
group by regionid
where regionid > 2
No comments:
Post a Comment