Click here to Skip to main content
16,019,768 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Am trying to query a table to get max,min and max-1 values based on IDs.Here i need to get the details of all projects from the subquery 'b' but am getting null values for most of the columns -A.SCAN_ID AS PRIOR_SCAN which is not supposed to be.

What I have tried:

select a.PROJECT,
a.SOLUTION,
a.first_scan,
a.last_scan,
b.PRIOR_SCAN
from
(
SELECT PROJECT,SOLUTION,MIN(SCAN_ID)first_scan, MAX(SCAN_ID)last_scan
FROM PORTAL_CSA.RPT_Scan_Summary
GROUP BY PROJECT,SOLUTION)a
LEFT OUTER JOIN
(
SELECT A.SOA_SECTOR, A.PROJECT,A.SOLUTION, A.SCAN_ID AS PRIOR_SCAN
FROM
(SELECT DISTINCT SOA_SECTOR, PROJECT,SOLUTION, SCAN_ID,
DENSE_RANK() OVER (PARTITION BY PROJECT,SOLUTION ORDER BY SCAN_ID DESC) AS PRIOR_SCAN_ID FROM PORTAL_CSA.RPT_Scan_Summary) A
WHERE A.PRIOR_SCAN_ID = 2 )b ON b.PROJECT =a.PROJECT AND b.SOLUTION =a.SOLUTION
Posted
Updated 21-Jul-18 3:09am
v2
Comments
MadMyche 20-Jul-18 15:27pm    
Can you post some sample data along with the results you expect from that data
GJSS 20-Jul-18 15:38pm    
Insert into EXPORT_TABLE (PROJECT,SOLUTION,FIRST_SCAN,LAST_SCAN,PRIOR_SCAN) values ('park.Cash.Trading.csproj','TWSTicketing.sln',2491149,2514275,2514274);
Insert into EXPORT_TABLE (PROJECT,SOLUTION,FIRST_SCAN,LAST_SCAN,PRIOR_SCAN) values ('RBCheck.Services.ArchiveAndPurgeService.csproj','RB.Citi.GlobalCheck.sln',1989546,5385142,5384987);
Insert into EXPORT_TABLE (PROJECT,SOLUTION,FIRST_SCAN,LAST_SCAN,PRIOR_SCAN) values ('Cmb.UI.Framework.Core.csproj','BE2UI.sln',51839,61995,61994);
GJSS 20-Jul-18 15:41pm    
Here i want to fetch the column value of A.SCAN_ID AS PRIOR_SCAN for all the projects returning from subquery 'a'.
Rowcount of subquery -15999
rowcount of whole query -16824

Santosh kumar Pithani 21-Jul-18 7:31am    
Hello GJSS, use inner join instead of left join in your query.please read about left join you will understood better why you got nulls.

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900