This question already has answers here:
SQL - HAVING vs. WHERE (9 answers)
Closed 2 days ago.
I want the count()
function query return value if count is greater than 0 in SQL Server.
I am using this query, but it returns created date-wise count. If I remove created column from group then it causes an error.
select count(*) as error_count
from error_info
group by created
having count(*) > 0
and convert(datetime, created) >= '2022-12-01 10:01:41.000'
and convert(datetime, created) < '2022-12-07 08:59:08.290'
As per my requirement, this query should return total records as count between given dates only if records exist in table. it should not return 0 count.
I want total records as count between given dates only if greater than 0.
1条答案
按热度按时间6ie5vjzr1#
在
where
子句中使用筛选器,而不在having
中