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

How show mysql query without NULL?

How show mysql query without NULL?
I want to show my quary where "LAG(title) OVER(PARTITION BY emp_no)" IS NOT NULL, I need only titles.emp_no = "LAG(title) OVER(PARTITION BY emp_no)"

My query:

SELECT titles.emp_no, LAG(title) OVER(PARTITION BY emp_no)
FROM titles;

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

enter image description here

>Solution :

Subquery your current query and filter based on the lag value:

WITH cte AS (
    SELECT emp_no, LAG(title) OVER (PARTITION BY emp_no ORDER BY <col>) lag_title
    FROM titles
)

SELECT emp_no, lag_title
FROM cte
WHERE lag_title IS NOT NULL;

Notice that I added an ORDER BY clause to LAG, without which is does not make much sense.

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