iphone
css
android
ruby-on-rails
mysql
objective-c
multithreading
eclipse
silverlight
flash
html5
perl
oracle
cocoa
apache
mvc
asp
api
postgresql
dom
I didn't see any purpose for the someVal1, someVal2, and someVal3 fields, so I left them out. I used an autonumber as the primary key instead of your date/time field; but this approach should also work with your date/time primary key. This is the data in my version of your table.
pkey_field target 1 A 2 A 3 A 4 B 5 B 6 A
I used a correlated subquery to find the previous pkey_field value for each row.
SELECT m.pkey_field, m.target, (SELECT Max(pkey_field) FROM YourTable WHERE pkey_field < m.pkey_field) AS prev_pkey_field FROM YourTable AS m;
Then put that in a subquery which I joined to another copy of the base table.
SELECT sub.pkey_field, sub.target, sub.prev_pkey_field, prev.target AS prev_target FROM (SELECT m.pkey_field, m.target, (SELECT Max(pkey_field) FROM YourTable WHERE pkey_field < m.pkey_field) AS prev_pkey_field FROM YourTable AS m) AS sub LEFT JOIN YourTable AS prev ON sub.prev_pkey_field = prev.pkey_field WHERE sub.prev_pkey_field Is Null OR prev.target <> sub.target;
This is the output from that final query.
pkey_field target prev_pkey_field prev_target 1 A 4 B 3 A 6 A 5 B
Here is a first attempt,
SELECT t1.Row, t1.target FROM t1 WHERE (((t1.target)<>NZ((SELECT TOP 1 t2.target FROM t1 AS t2 WHERE t2.DateTimeId<t1.DateTimeId ORDER BY t2.DateTimeId DESC),"X")));