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

247
Vistas
SQL SUM and DISTINCT two columns

I have a table called points and based on distinct values of entires, I want to sum valid entries.

I have this:

valid_entries Codes
1 768
2 1224
2 1224
1 512
1 512

Based on distinct values I would have:

valid_entries codes
1 768
2 1224
1 512

I want to get the sum of valid_entries that would be 4.

I have tried this one and I have PostgreSQL 11.5 version and I am new to this. I would really appreciate it if anyone could help with this.

SELECT sum(valid_entries) FROM 
(SELECT count(distinct(codes)) FROM points WHERE  participant_id='123') t
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First filter out the duplicate rows with DISTINCT and then aggregate:

SELECT SUM(valid_entries) total
FROM (SELECT DISTINCT valid_entries, Codes FROM points WHERE participant_id='123') t;

See the 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