Hi @ooj-4672
You can learn to use CTE. It can make your code intuitive.
Just like this.
;with T1 as(
select * from MyTable where Left(op,2) = 'al'
),T2 as(
select *,row_number()over(partition by deptno order by eid) as rownumber from T1)
select * from T2 where rownumber < 4;
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.