Problems in select using Having MAX non-boolean expression

Asked

Viewed 69 times

0

I need to make a select to pick up all the patients who have been consulted over a period of time in a specific sector, and see when their last comeback was, and if they are more than a year old not coming in that same sector, and then another very similar select but then they even returned for other queries, but not in this sector X

The incial part of the select is

SELECT DISTINCT osm_pac, osm_dthr 
FROM osm 
WHERE osm_serie BETWEEN 115 AND 119  
AND osm_str = 'GLA' 
GROUP BY osm_pac 
HAVING MAX (osm_dthr)

that when I’m giving that having max the compiler turns me around

An expression of non-boolean type specified in a context where a condition is expected, near ')'.

This in theory would bring the patients who consulted in the GLA sector with their last care date.

Of course for now these values are only numerical, after which I will do the Join with the table where the names of the patients are

1 answer

1

Cara I believe I missed comparing the patient code in the clause having:

SELECT DISTINCT osm_pac, osm_dthr 
FROM osm 
WHERE osm_serie BETWEEN 115 AND 119  
AND osm_str = 'GLA' 
GROUP BY osm_pac 
HAVING MAX (osm_dthr) = osm_dthr
  • Hello Germano! Your help was essential! ;sql
SELECT DISTINCT osm_pac, osm_dthr 
FROM osm 
WHERE osm_serie BETWEEN 115 AND 119 
AND osm_str = 'GLA' 
GROUP BY osm_pac, osm_dthr
HAVING MAX (osm_dthr) = osm_dthr


Browser other questions tagged

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