I have table where I have some sent sms'es by operaters and some by users, in both cases in column PhoneNumber is users phone
{PhoneNumber Date Type SMS Response}
Type is 1 or 2, when value is 1, message is sent by operater, when value is 2, message is sent by user. In first case, there is response filled, in second, there is SMS.
I need to show messages sent by operaters and replies by users.
If this is example (sorted by time):
user message 1
user message 2
operators message 1
operators message 2
operators message 3
users message 3
users message 4
it should be sorted like this:
operators message 1 null
operators message 2 null
operators message 3 users message 3 users message 4
(I "selected just" row with messages)
so this is my idea, to separate users and operaters message in two temp tables, and left join them on PhoneNumber = PhoneNumber, but I dont know to do those time conditions.
Basically any solutions that will list operaters messages and answer (that should be determined by times, if three operators messages in row and then users message, its answerd on third, and for first two answer should be null, and users messages before first operators message are not important).
I did my best to explain, if you have questions, please ask, and thanks in advance for any ideas.