Return larger date without repeating ids

Asked

Viewed 23 times

-2

I need to return to the highest date without repeating id.

I need a table with:

  • Customer id
  • Date of last download
  • Number of text messages sent to the ID
  • Date of last text message
  • Date of the signup

inserir a descrição da imagem aqui

On the date of the last SMS is the problem, I tried the MAX but it didn’t work, keeps duplicating ID.

Code that I used:

SELECT DISTINCT
otx.MID,
DATE (otx.ultimo_download),
COUNT (cm."OwnerId") AS "Qtd_sms_send",
MAX (cm.sms_date") AS "último_sms",
DATE (om.signup_date) AS "Signup_date"

Whereas: otx contains the customer, om the registration data and cm every communication sent.

What I want is the photo table with only one user per line. Example:

MID 111298 | último download 25/08/2021 | qtd_sms 2 | último sms 18/05/2021 | signup 2013-10-23
  • "continues to duplicate ID." some other field is duplicating the results... start with a field and gradually add the others, for example select id from tabela group by id, and then add the others until you figure out what you’re duplicating

  • The junction of the various tables is being poorly done or the BD scheme has some problem. But since the BD schema was not shared (neither the schema nor the full search command) it is difficult to identify the problem. But, except in particular cases, the use of DISTINCT in conjunction with GROUP BY does not add value....

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.