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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -