Link a Query results with a Table
Hi folks,
This is very useful when we use query results with a table.
for example
here i have written query to get the sum of books from one table then i join that query resultset with another table in which i have sum up.
with chequedet(
BCode,NoofLeaves,TTLBooks)
as
(
select BCode,NoofLeaves,sum(NoofBooks) TTLBooks from ChequeDetails
where JobNo='xxxxxxx'
group by BCode,NoofLeaves
)
select a.bcode,b.NoofLeaves, b.TTLBooks,sum(a.noofbooks)
from ChequeDetails a ,chequedet b
where a.BCode=b.BCode and JobNo='xxxxxxx'
group by a.bcode,b.NoofLeaves,b.TTLBooks
order by a.bcode,b.NoofLeaves, b.TTLBooks
This is very useful when we use query results with a table.
for example
here i have written query to get the sum of books from one table then i join that query resultset with another table in which i have sum up.
with chequedet(
BCode,NoofLeaves,TTLBooks)
as
(
select BCode,NoofLeaves,sum(NoofBooks) TTLBooks from ChequeDetails
where JobNo='xxxxxxx'
group by BCode,NoofLeaves
)
select a.bcode,b.NoofLeaves, b.TTLBooks,sum(a.noofbooks)
from ChequeDetails a ,chequedet b
where a.BCode=b.BCode and JobNo='xxxxxxx'
group by a.bcode,b.NoofLeaves,b.TTLBooks
order by a.bcode,b.NoofLeaves, b.TTLBooks
Comments
Post a Comment