我从这个查询中获得了重复的行,请感谢您的帮助。
select
Id_num
Street
Town
Incidents
IncidentType A
IncidentType B
IncidentType C
FROM OPENQUERY
(POSTGRESQL,
Id_num
Street
Town
Incidents
IncidentType A
IncidentType B
IncidentType C
FROM
(
select
COUNT(i.Id_num) as Incidents,
COUNT(case when i.INC_TYPE = ''A'' THEN 1
end)
"IncidentType A"
COUNT(case when i.INC_TYPE = ''B'' THEN 1
end)
"IncidentType B"
COUNT(case when i.INC_TYPE = ''C'' THEN 1
end)
"IncidentType C"
FROM Table i
WHERE I.CALL_TIME >= (now()-(''12 months'' ::interval))
GROUP BY i.Id_num
HAVING COUNT (i.Id_num) > 1
) i
结果是返回一些重复
Id_num Street Incidents IncidentType A IncidentType B IncidentType C
32 back lane 5 3 0 2
32 back lane 5 3 0 2
我已尝试SELECT DISTINCT ON
Id_num
,但仍然会重复。