rogerzebra
Technical User
Hi guys,
I was hoping for some help with my little problem. I’m using previous status together with previous date if the current status is not what I want. The table is joined twice so I can use table b’s date is less then table’s a date to use previous date. The my problem is that when I use the group by clause the b.status column its not taking any regards to the max(date) statement in the where clause. Instead of showing me 1 single result it showing me all different statuses. I know this should be very easy to figure out but I can’t see what I’m doing wrong. So, please how do I filter it out so that the b.status only showing the current status together with the max(date). I appreciate all efforts. Thx
I was hoping for some help with my little problem. I’m using previous status together with previous date if the current status is not what I want. The table is joined twice so I can use table b’s date is less then table’s a date to use previous date. The my problem is that when I use the group by clause the b.status column its not taking any regards to the max(date) statement in the where clause. Instead of showing me 1 single result it showing me all different statuses. I know this should be very easy to figure out but I can’t see what I’m doing wrong. So, please how do I filter it out so that the b.status only showing the current status together with the max(date). I appreciate all efforts. Thx
Code:
Select a.status
b.status
max(a.Date)
max(b.Date)
from t1 a
left join t1 b on a.x = b.x
and a.Date > b.Date
where a.pol = ‘xxxxx’
and b.Date = (select max(c.Date)
from t1 c
where c.id = b.id
)
Group by a.status
b.status