sql server - SQL group by in joined tables -


i trying extract data 2 tables of sql server. below query runs out "group by" when try group data b.catdesc , a.fiscal_ year shows below error.

error: [ibm][system access odbc driver][db2 i5/os]sql0122 - column country_code or expression in select list not valid. error code: -122 report user

select  a.country_code, a.book, b.catunitdesc, b.catdesc, b.csku_cc, sum(a.gross_sales), a.fiscal_year, a.fiscal_week, a.fiscal_month, sum(a.gross_costs), sum(a.net_sales), sum(a.net_costs), sum(a.qty_shipped_gross), sum(a.qty_shipped_net)  essv11.eudmeas2 join essv11.eudmp1 b on a.sku_cc = b.sku_cc  book = 'g21-2014'  or book = 'g21-2015' or book = 'g21-2016' , country_code ='gb'  grouped b.catdesc, a.fiscal_year; 

can please help.

thanks in advance

you need include non-aggregated columns in group by. suggest:

select  a.country_code, a.book, b.catunitdesc, b.catdesc, b.csku_cc,         sum(a.gross_sales),         a.fiscal_year, a.fiscal_week, a.fiscal_month,         sum(a.gross_costs),         sum(a.net_sales),         sum(a.net_costs),         sum(a.qty_shipped_gross),         sum(a.qty_shipped_net) essv11.eudmeas2 join      essv11.eudmp1 b      on a.sku_cc = b.sku_cc book in ('g21-2014', 'g21-2015', 'g21-2016') ,       country_code = 'gb'  group a.country_code, a.book, b.catunitdesc, b.catdesc, b.csku_cc,          a.fiscal_year, a.fiscal_week, a.fiscal_month; 

note:

  • the group by has non-aggregated columns.
  • in better series of =/or

Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -