Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
Unique records quarter over quarter

I have a table like so -

patient_id   date            org
I5434        2020-06-05      Methodist Hospital
ertw4        2020-08-03      New York Hospital
ouiku35      2020-08-30      Tristar 
ouiku35      2020-01-05      Tristar
ouiku35      2020-04-22      Tristar 

The output I am needing is

quarter   count
2020Q1    1
2020Q2    1 
2020Q3    1 

3rd record in the table above is not counted because it is the same patient in prior quarters at the same hospital

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

We can try using a calendar table approach here:

WITH quarters AS (
    SELECT 2020 AS year, 1 AS quarter, '2020Q1' AS label UNION ALL
    SELECT 2020, 2, '2020Q2' UNION ALL
    SELECT 2020, 3, '2020Q3' UNION ALL
    SELECT 2020, 4, '2020Q4'
)

SELECT q.label, COUNT(t.date) AS count
FROM quarters q
LEFT JOIN yourTable t
    ON EXTRACT(year FROM t.date) = q.year AND
       EXTRACT(quarter FROM t.date) = q.quarter
GROUP BY q.label
ORDER BY q.label;

screen capture from demo link below

Demo

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda