sql - ERROR! - Cannot use an aggregate or a subquery in an expression used for the group by list of a GROUP BY clause -


i'm getting error: cannot use aggregate or subquery in expression used group list of group clause.

i've looked around can not find me in case.

i using sql server 2012

select distinct  commoditycode.commoditycode comcode,  facility.facilityacctnum,  vessel.vesseltype,  facility.facilitynm,   case       when commodities.shippedreceivedid = 'r' , commodities.foreigndomesticid = 'f'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end recf,       case       when commodities.shippedreceivedid = 'r' , commodities.foreigndomesticid = 'd'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end recd,       case       when commodities.shippedreceivedid = 's' , commodities.foreigndomesticid = 'd'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end shipped,       case       when commodities.shippedreceivedid = 's' , commodities.foreigndomesticid = 'f'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end shippedf, commodities.destination, commodities.origin,  commodities.specific,  commoditycode.descr,  facility.facilityid,  transactioncharge.arrivaldt,  transactioncharge.departdt,  transactioncharge.dtdocked,  transactioncharge.dtsailed  vessel  inner join commodities  inner join commoditycode on commodities.commoditycode = commoditycode.commoditycode  inner join transactioncharge on commodities.transactionid = transactioncharge.transactionid on vessel.vesselid = transactioncharge.vesselid  inner join facility on transactioncharge.facilityid = facility.facilityid  inner join unit on commodities.unit = unit.unit  inner join transactionfee on transactioncharge.transactionid = transactionfee.transactionid  group  commoditycode.commoditycode,  facility.facilityacctnum,  vessel.vesseltype,  facility.facilitynm,  commodities.destination,  commodities.origin,  commodities.specific,  commoditycode.descr,  facility.facilityid,  case       when commodities.shippedreceivedid = 'r' , commodities.foreigndomesticid = 'f'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2          )          end       else 0       end,       case       when commodities.shippedreceivedid = 'r' , commodities.foreigndomesticid = 'd'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end,       case       when commodities.shippedreceivedid = 's' , commodities.foreigndomesticid = 'd'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end,       case       when commodities.shippedreceivedid = 's' , commodities.foreigndomesticid = 'f'      case when commodities.amount null or commodities.unit null null         else         round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode               commoditycode.commoditycode = commodities.commoditycode)         else (select shorttonfactor unit               unit.unit = commodities.unit) end,2           )          end       else 0       end, transactioncharge.arrivaldt,  transactioncharge.departdt,  transactioncharge.dtdocked,  transactioncharge.dtsailed  having (vessel.vesseltype='v' or vessel.vesseltype='o') 

you have subqueries in case statement in group by. example, looking @ first part of case statement:

when commodities.shippedreceivedid = 'r' , commodities.foreigndomesticid = 'f'  case when commodities.amount null or commodities.unit null null     else     round (commodities.amount/case when commodities.unit = 'b' (select bushelfactor commoditycode           commoditycode.commoditycode = commodities.commoditycode)     else (select shorttonfactor unit           unit.unit = commodities.unit) end,2      )      end   else 0   end, 

there 2 there start with, beginning select bushelfactor... , select shorttonfactor..., have remove them.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -