WITH temp AS
( SELECT Customer_ID,Date_of_Booking,Booking_ID, No_of_Booking
FROM (
SELECT Customer_ID,Date_of_Booking,Booking_ID, No_of_Booking, row_number() OVER ( partition BY Customer_ID ORDER BY Date_of_Booking) rnum
FROM urtable) temp1
WHERE rnum <= 3 )
SELECT t1.Date_of_Booking, t1.No_of_Booking, t2.Date_of_Booking, t2.No_of_Booking, t3.Date_of_Booking, t3.No_of_Booking
FROM temp t1
LEFT OUTER JOIN temp t2 ON t1.Customer_ID = t2.Customer_ID
LEFT OUTER JOIN temp t3 ON t1.Customer_ID = t3.Customer_ID
|