sql - I want to fetch this data year wise -
select cidetail.itemname, sum(cidetail.taxamount+ cidetail.lineamount) [totalamount] cidetail (nolock) inner join ciheader on cidetail.invoiceno= ciheader.invoiceno ciheader.invoicedate between '2010-04-01' , '2014-04-01' group cidetail.itemname
have derived table use ansi sql's extract
year part out of date, , add amounts together. @ main level group by
both itemname , year:
select itemname, "year", sum(amount) totalamount ( cidetail.itemname, extract(year ciheader.invoicedate) "year", cidetail.taxamount + cidetail.lineamount amount cidetail (nolock) inner join ciheader on cidetail.invoiceno= ciheader.invoiceno ) dt group itemname, "year"
no dbms tagged in question, if dbms doesn't support extract
, try year(ciheader.invoicedate)
example, or else.
Comments
Post a Comment