通过计数>获得使用组的总计数1

时间:2016-01-08 16:36:10

标签: sql oracle

我正在寻找桌上猫图案的多个点。

select spot_pattern, count(*) from cat_pattern group by spot_pattern having count(*) > 1;

这会有用吗?

1 个答案:

答案 0 :(得分:1)

您是否想要获取此信息?

declare @t table(
id int,
datet date
)


insert into @t
select 101,'01/01/2015' union
select  101,'01/02/2015' union
select  101,'04/01/2015' union
select  201,'01/01/2015' union
select  201,'01/03/2015' union
select  301,'05/01/2015' union
select  401,'06/01/2015' union
select  401,'07/01/2015' union
select  401,'07/02/2015'

Select T.ID, T.Total, Coalesce(C.Total, 0) As CountDtGaps
From 
(Select Id, count(*) As Total From @t Group By Id) As T
Left Outer Join (Select Id, count(*) As Total From @t Where datet < dateadd(dd, -90, Cast(getdate() as date)) Group By Id) As C
On T.Id = C.Id

--PS. r u sure about results expected? 90 days ago.. all rows are selected.