【发布时间】:2020-09-09 12:41:22
【问题描述】:
如果过去 3 个月中的任何一个月的值>=3,我想过滤该值。查看我在输出中需要突出显示的图像。
我尝试过的查询。
select Application_Infrastructure,year,month_name,count(ticket_no) as 'CN' from [service_delivery]
where month_num in (MONTH(getdate()),MONTH(getdate())-1,MONTH(getdate())-2,MONTH(getdate())-3)
group by Application_Infrastructure,year,month_name
having count(ticket_no)>=3
order by Application_Infrastructure,CN
having count(ticket_no)>=3 正在消除该月小于 3 的值。
【问题讨论】:
-
请向我们展示生成当前结果的查询。
-
你试过什么?为什么它不起作用?在您忘记包含在问题中的查询之前,您的数据是什么样的(也不要使用数据图像,将其提供为表格格式的
text或 DDL 和 DML 语句)。此外,现在完全不支持 SQL Server 2008;我强烈建议您在(非常)不久的将来优先升级。 -
我以该数据为例,查询是 select Application_Infrastructure,year,month_name,count(ticket_no) as 'CN' from [service_delivery] where month_num in (MONTH(getdate()),MONTH( getdate())-1,MONTH(getdate())-2,MONTH(getdate())-3) 按 Application_Infrastructure,year,month_name 分组,count(ticket_no)>=3 order by Application_Infrastructure,CN 这消除了不大于 3 ,但对我来说,如果任何月份值大于 3,则必须显示整个 Application_Infrastructure 数据。
-
edit 你的问题@MUHAMMEDTHAYYABSAWOODSYED。 cmets 是针对 cmets 的,而不是针对您的问题中应该包含的信息。
-
谢谢拉努,我已经编辑了这个问题。
标签: sql sql-server tsql sql-server-2008 group-by