select *
from (
select CustomerID,Country,
LAG(CustomerID,1,'') Over(order by Country,CustomerID) as Lag,
LEAD(CustomerID,1,'') Over(order by Country,CustomerID) as Lead
from Customers
--Group by CustomerID,Country
) as a
where 'MAISD' in (CustomerID,Lag,Lead)
Chỉ áp dụng cho sql 2012 trở lên.
0 blogger:
Đăng nhận xét