I have a problem that I have built a sort of solution to which seems to work in 99% of cases but I am sure there must be an easier solution to this.
I have a table with a load of records of differing types (they are types of sales with a sales identifier number). What I need to do is to select for each person in a given period a random type of sale with the identifier in week 1 then in week 2 try to select a different type unless all that perosn has sold is the same type as week 1.
My current solution involves row_number and then selections based on where exists and not exists. Does anyone know if there is a much easier solution to do this?
I have a table with a load of records of differing types (they are types of sales with a sales identifier number). What I need to do is to select for each person in a given period a random type of sale with the identifier in week 1 then in week 2 try to select a different type unless all that perosn has sold is the same type as week 1.
My current solution involves row_number and then selections based on where exists and not exists. Does anyone know if there is a much easier solution to do this?