'Creating a new variable based on values of previous rows in impala sql

Hi I have this data set

ID   DATE      PROCEDURE  WANT_VARIABLE (check previous procedure?)

1  03/01/2022   MRI        NO            here ID 1 didnot had MRI before so no 
1  03/06/2022   CT         NO            here ID 1 didnot had ct before so no
1  03/15/2022   MRI        YES           here ID 1  had MRI before so YES
2  03/08/2022   CT         NO            here ID 2 didnot had CT before so no
2 03/18/2022    CT         YES           here ID 2 had CT before so yes

what I want is a want_variable which look for previous rows value in procedure if they had same procedure in previous dates then say yes then say no

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source