Reputation: 49
I have a SQL table that looks like this
I'd like to group by System to show if all tasks are done or not (if all statuses for a system are done then Done else Not Done).
Upvotes: 1
Views: 64
Reputation: 2460
You could use MAX()
with GROUP BY
. Assuming those are the only two available values for your status column.
SELECT Name, System, MAX(Status) Status
FROM Table
GROUP BY Name, System
Upvotes: 1
Reputation: 324
SELECT DISTINCT
Name,
System,
CASE
WHEN (SELECT NULL AS [Empty] FROM Table AS t_inner WHERE t_inner.Status = 'Not Done' AND t_inner.System = t_outter.System AND t_inner.Name = t_outter.Name) EXISTS
THEN 'Not Done'
ELSE 'Done'
END
FROM
Table AS t_outter
Upvotes: 0
Reputation: 31795
Select Distinct Name/System, and then use a subquery for the Status.
The subquery could be a CASE WHEN EXISTS() structure.
Upvotes: 0