Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mysql compare different rows

i have the following table
id | user | date | value. I need to find users that have values on eg October month but they dont have on November month.
I ve tried the following code around.

select *
from users B 
LEFT OUTER JOIN data A 
on A.user = B.user
Where B.permissions=1 AND A.date BETWEEN '2021-11-01' AND '2021-11-30' group by A.user 

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

select *
from users as usr
where permissions = 1
  and exists (     -- have data for october 2021
    select 1
    from data AS d
    where d.user = usr.user
      and d.date BETWEEN '2021-10-01' AND '2021-10-31' 
  )
  and not exists ( -- no data for november 2021
    select 1
    from data AS d
    where d.user = usr.user
      and d.date BETWEEN '2021-11-01' AND '2021-11-30' 
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading