I have previously posted in: Aggregating based on grouping of multiple columns. After two weeks of trying subqueries and analytical functions to do a basic COUNT and GROUP BY of 7 columns, I think that I discovered my source of error was that the DATE field. (Through trial and error of all of the other columns, the COUNT properly aggregates to 1 count row grouped by the 6 columns.)
Now, the question remains: is there something that I can do to ensure that I am only bringing back distinct dates for the format DD MMM YY (without times)? Based on this post, it seems like perhaps the issue is that I am bringing back times with the date even though ORACLE only shows the date portion? Date column in oracle. Any pointers on CASTING the DATE_STARTED value so that I can use the initial WHERE clause to filter my initial search and then later use DATE like a string to make a UUID?
My code so far (with some code removed e.g., … = CASE STATEMENT to create an additional column, ANALYSIS_TYPE_ALIAS ):
WITH TALLY as (
SELECT PERSON.NAME, PERSON.PHASE, TEST.DATE_STARTED, TEST.ANALYSIS, SPECIMEN.GROUP, TEST.STATUS,
ANALYSIS.ANALYSIS_TYPE...
FROM DB.TEST
INNER JOIN
DB.SAMPLE ON
TEST.SPECIMEN_NUMBER = SPECIMEN.SPECIMEN_NUMBER
INNER JOIN
DB.PRODUCT ON
SPECIMEN.PERSON = PERSON.NAME
INNER JOIN
DB.ANALYSIS ON
TEST.ANALYSIS = ANALYSIS.NAME
WHERE PERSON.NAME = 'Joe'
AND TEST.DATE_STARTED >= '20-DEC-18' AND TEST.DATE_STARTED <='03-APR-19'
AND PERSON.PHASE = 'PHASE1'
ORDER BY TEST.DATE_STARTED),
SUMMARY_COMBO AS (SELECT DISTINCT(TALLY.DATE_STARTED), CONCAT(CONCAT(CONCAT(CONCAT(DATE_STARTED,ANALYSIS),STATUS), GROUP), ANALYSIS_TYPE_ALIAS) AS UUID,
TALLY.NAME, TALLY.PHASE,TALLY.ANALYSIS,TALLY.GROUP, TALLY.STATUS, ANALYSIS_TYPE_ALIAS
FROM TALLY)
SELECT SUMMARY_COMBO.NAME,SUMMARY_COMBO.PHASE,SUMMARY_COMBO.ANALYSIS, SUMMARY_COMBO.GROUP,SUMMARY_COMBO.STATUS,SUMMARY_COMBO.ANALYSIS_TYPE_ALIAS,SUMMARY_COMBO.UUID,
COUNT(SUMMARY_COMBO.UUID) AS S_COUNT
FROM SUMMARY_COMBO
GROUP BY SUMMARY_COMBO.NAME,SUMMARY_COMBO.PHASE,SUMMARY_COMBO.ANALYSIS,SUMMARY_COMBO.STATUS,SUMMARY_COMBO.ANALYSIS_TYPE_ALIAS,SUMMARY_COMBO.UUID
HAVING COUNT(*) >=1
ORDER BY UUID;
This yields something like this:UUID produces COUNT for each date
Ideally, I could also include the DATE_STARTED as well. When I currently try to include DATE_STARTED, the aggregation does not work, as the S_COUNT is 1 for each permutation.
Any advice is greatly appreciated.