question

buntysoft avatar image
buntysoft asked

Sql query to find status by grouping by custname

I have custname e.g. aa bb cc bb
Status as blank blank blank completed and status time as 13:00 14:000 14:00 16:00

I want the output with only blank status and not the completed so output I am looking for is

aa 13:00
CC 14:00

And since bb already completed I dont want the output of that

sql query
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

· Write an Answer
anthony.green avatar image
anthony.green answered

What have you tried so far?


Essentially you want to do a self join or a where filter to filter out any custnames where any of the records is completed


select custname, max(statustime) as statustime

from <SOMETABLE>

where custname not in (select custname from <SOMETABLE> where statuscode = 'completed')

group by custname


10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.