The below query works perfectly when there are rows. Output as:
Duplicates,2
Syntax,5
Total,7
However I need to return a row of Total, 0 when there are no rows.
Have tried changing the INNER JOIN to a RIGHT JOIN but this then returns two rows. Total,0 Total,0
I probably could work with that and strip the extra one in my VB code but would like to work out how to do it within the SQL.
SELECT
nvl(to_char(dbms_lob.substr(message, 50, 1 )),'Total') AS TYPE ,
Count(dbms_lob.substr( message, 50, 1 )) AS "HOWMANY"
FROM applicationlogentries ALE
INNER JOIN (
SELECT REFERENCE_ID , Max(entry_date) AS MaxDateTime
FROM APPLICATIONLOGENTRIES
where Trunc(entry_date) = Trunc(SYSDATE) -8
GROUP BY REFERENCE_ID) groupedAle
ON ale.reference_id = groupedAle.reference_id
AND ale.last_updated = groupedAle.MaxDateTime
AND ale.reference_id IN
(SELECT ID FROM documentsin
where Trunc(date_received) = Trunc(SYSDATE) -8 AND
status = 3)
group by grouping sets((),(dbms_lob.substr( message, 50, 1 )))