I need some assistance and guidance.
I want to retrieve a summary of results based on values in another column. For example, I have a column in my data set that shows an audit date. There will be some records which will have an empty audit date, in that case I want to display summary results based on it which where so long as there is a specific date which is empty,a value will be assigned to it based on its grouping. I have made a sample illustration of the problem below:
ORIGINAL TABLE :
Table A
+--------------+--------------+--------------+
| officecode | Username | auditdate |
+--------------+--------------+--------------+
| ABC | ABCTOM | 02-Dec-2012 |
| ABC | ABCPET | 08-Dec-2012 |
| ABC | ABCLEE | 12-Dec-2012 |
| ABC | ABCHET | 25-Dec-2012 |
| DEF | DEFJKT | 23-Dec-2012 |
| DEF | DEFGET | 12-Dec-2012 |
| DEF | DEFHTT | 18-Dec-2012 |
| DEF | DEFEET | 16-Dec-2012 |
| XYZ | XYZOOP | 16-Dec-2012 |
| XYZ | XYZIOO | |
| XYZ | XYZJMN | 16-Dec-2012 |
| XYZ | XYZGHB | |
+--------------+--------------+--------------+
INTENDED RESULT :
+------------+------------+
| officecode | audit_status
+------------+------------+
| ABC | Complete |
| DEF | Complete |
| XYZ | Incomplete |
+------------+------------+
I've done some research and tried pairing group by with a case but i seem to not be getting the results.
SELECT distinct officecode,
CASE WHEN auditdate IS NULL
THEN 'INCOMPLETE'
WHEN auditdate IS NOT NULL
THEN 'COMPLETE'
END AS AUDIT_STATUS
FROM A GROUP BY officecode;