I’m working on a relatively simple query at this stage and I’m wondering how I can derive a single row of data when there is a change in column data (status). I know this sounds like jumble, I’m just not sure how to put it in correct terms so, I’m just going to show you!
I’m trying to extract the highest datestamp in column (whse_load_ts) where column (whse_ac) does not have a value of Y. I want this to return one row.
C_CLM C_STA_CLM WHSE_ACTN_CD WHSE_CURR_ROW_IND WHSE_LOAD_TS
12056733 AC U 2012-05-30 03:18:12
Currently it is returning two rows because of the change in status c_sta_clm.
C_CLM C_STA_CLM WHSE_ACTN_CD WHSE_CURR_ROW_IND WHSE_LOAD_TS
12056733 AC U 2012-05-30 03:18:12
12056733 PC U 2012-04-28 03:19:38
All of the data for this specific claim looks like this:
12056733 PC I 2012-02-04 03:20:25.150
12056733 PC U 2012-02-07 03:19:43.230
12056733 PC U 2012-02-11 03:21:31.440
12056733 PC U 2012-04-28 03:19:38.380
12056733 AC U 2012-05-17 03:18:25.920
12056733 AC U 2012-05-19 03:20:33.200
12056733 AC U 2012-05-30 03:18:12.370
12056733 TE U Y 2012-06-06 03:20:07.520
Query is as follows
SELECT
c_clm,
c_sta_clm,
whse_curr_row_ind,
max(whse_load_ts) as "Loaded"
FROM
pearl_p.TLTC900_CLM_PRSST
WHERE
whse_curr_row_ind not in('y')
AND c_clm = '12056733'
group by 1,2,3
Basically it’s pulling the max date for each status AC/PC when i just want the max date for anything without a Y in the whse_curr_row_ind column
You can do this with a sub-query: