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

SQL QUERY to find the all senior citizen from table

enter image description hereselect * from patient where age as datediff(pdob,’2022-06-11′)>=75;

why is this query is giving an empty set?

My question is:- Find all the patients who can avail of senior citizen discount.

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

>Solution :

The problem of DATE_DIFF is that it outputs the difference in days. If you want a difference in years, you can use DATE_ADD:

SELECT * 
FROM patient 
WHERE DATE_ADD(pdob, INTERVAL 75 YEAR) < '2022-06-11'

Check the demo here.

Note: if you really want to use DATE_DIFF, you need to transform 75 years into days and use that value.

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