I have a table data with many columns(date,query,position) and I need to get query(distinct) column with first occurrence, 2nd occurrence and last occurrence, also differenc