Hi All,
Am using Partition by in query to fetch last record from each group. but same query giving me different result when using in SQLRPGLE and STRSQL.
Query in SQLRPGLE:-
Select Count(*) into :Wk9Count from FileA where
Product = :Wk9Prod and Customer_Id1 in (
Select Customer_Id2 from(Select Customer_Id2,Customer_Status,ROW_NUMBER() OVER
(PARTITION BY Customer_Id2
ORDER BY Date_1 Desc,Date_2 Desc,Date_3 Desc)
As row_number from File2)
as testfile where ROW_NUMBER=1 and Customer_Status = 'T' )
and SubString(Customer_State,1,2) = :Wk9State and Cust_info_date = 0;
Above query giving me count = 1.
Query in STRSQl:-
Select Count(*) from FileA where
Product = 'Prod1' and Customer_Id1 in (
Select Customer_Id2 from(Select Customer_Id2,Customer_Status,ROW_NUMBER() OVER
(PARTITION BY Customer_Id2
ORDER BY Date_1 Desc,Date_2 Desc,Date_3 Desc)
As row_number from File2)
as testfile where ROW_NUMBER=1 and Customer_Status = 'T' )
and SubString(Customer_State,1,2) = 'ST' and Cust_info_date = 0
This query giving count = 2.
Please suggest why am getting different result.
Thanks
Am using Partition by in query to fetch last record from each group. but same query giving me different result when using in SQLRPGLE and STRSQL.
Query in SQLRPGLE:-
Select Count(*) into :Wk9Count from FileA where
Product = :Wk9Prod and Customer_Id1 in (
Select Customer_Id2 from(Select Customer_Id2,Customer_Status,ROW_NUMBER() OVER
(PARTITION BY Customer_Id2
ORDER BY Date_1 Desc,Date_2 Desc,Date_3 Desc)
As row_number from File2)
as testfile where ROW_NUMBER=1 and Customer_Status = 'T' )
and SubString(Customer_State,1,2) = :Wk9State and Cust_info_date = 0;
Above query giving me count = 1.
Query in STRSQl:-
Select Count(*) from FileA where
Product = 'Prod1' and Customer_Id1 in (
Select Customer_Id2 from(Select Customer_Id2,Customer_Status,ROW_NUMBER() OVER
(PARTITION BY Customer_Id2
ORDER BY Date_1 Desc,Date_2 Desc,Date_3 Desc)
As row_number from File2)
as testfile where ROW_NUMBER=1 and Customer_Status = 'T' )
and SubString(Customer_State,1,2) = 'ST' and Cust_info_date = 0
This query giving count = 2.
Please suggest why am getting different result.
Thanks
Comment