CASE statement ALIAS comparison
<p>Here is my query:</p>

<pre><code>SELECT DISTINCT v.codi, m.nom, v.matricula, v.data_compra, v.color,
 v.combustible, v.asseguranca, 
(CASE WHEN lloguer.dataf IS NOT NULL THEN 'Si' ELSE 'Llogat'  END) AS Disponible 
FROM vehicle v 
INNER JOIN model m on model_codi=m.codi 
INNER JOIN lloguer on codi_vehicle=v.codi 
WHERE Disponible='Si';
</code></pre>

<p>What I'm trying to do it's to show only those rows that have the  "lloguer.dataf" is not NULL, but it doesn't alow me to use the "Disponible" alias to  do the last line comparison.</p>

<p>What can I do?</p>

<p>This is how the info is shown (with some more atribute) without the last line comparison.</p>

<p><a href="https://i.stack.imgur.com/ljhR3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ljhR3.png" alt="enter image description here"></a></p>