SELECT RECBILLNO , SUM(AMT) AS AMOUNT
FROM (SELECT A.RECBILLNO , B.QTY ,A.PRICE , (B.QTY *A.PRICE) AS AMT
FROM NY1 A INNER JOIN NY2 B ON A.RECBILLNO = B.RECBILLNO
) AS TB1
GROUP BY RECBILLNO
ORDER BY RECBILLNO
select y.recbillno,y.price,x.qty
from
(
select ROW_NUMBER() over ( partition BY recbillno order by recbillno) as no ,recbillno , price
from ny1
) as y
inner join
(
select ROW_NUMBER() over ( partition BY recbillno order by recbillno) as no ,recbillno , qty
from ny2
) as x on x.no = y.no and x.recbillno = y.recbillno
SELECT Y.RECBILLNO,Y.PRICE,X.QTY ,X.LOT
FROM
(
SELECT ROW_NUMBER() OVER ( PARTITION BY RECBILLNO ORDER BY RECBILLNO) AS NO ,RECBILLNO , PRICE
FROM NY1
) AS Y
INNER JOIN
(
SELECT ROW_NUMBER() OVER ( PARTITION BY RECBILLNO ORDER BY RECBILLNO) AS NO ,RECBILLNO , QTY , LOT
FROM NY2
) AS X ON X.NO = Y.NO AND X.RECBILLNO = Y.RECBILLNO